> For the complete documentation index, see [llms.txt](https://dynamicpixels.gitbook.io/dynamicpixels-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dynamicpixels.gitbook.io/dynamicpixels-docs/unity-sdk/multiplayer.md).

# Multiplayer

Explore the list of API functions available in Unity for multiplayer, including detailed descriptions and usage examples.

{% hint style="warning" %}
To use service functions, first ensure that the service is activated before. You can see services by opening "Service Hub" From the game's dashboard header.&#x20;
{% endhint %}

## Room Management

### Create Room[​](https://docs.dynamicpixels.dev/realtime/rooms#create-room) <a href="#create-room" id="create-room"></a>

Create a room in initial state

```csharp
var room = await ServiceHub.Services.MultiPlayer.RoomService.CreateRoom(new CreateRoomParams
{
    Name = "room name",
    IsPrivate = false,
    IsPermanent = false,
    MinPlayer = 0,
    MaxPlayer = 0,
    MinXp = 0,
    MaxXp = 1000,
    Status = RoomStatus.Initial,
    IsTurnBasedGame = false,
    GameOrderType = GameOrderType.RoundRobin,
    Metadata = "any data",
    Players = null
});
```

### Create Room and Open it[​](https://docs.dynamicpixels.dev/realtime/rooms#create-room-and-open-it) <a href="#create-room-and-open-it" id="create-room-and-open-it"></a>

Create a room in initial state

```csharp
var room = await ServiceHub.Services.MultiPlayer.RoomService.CreateAndOpenRoom(new CreateRoomParams
{
    Name = "room name",
    IsPrivate = false,
    IsPermanent = false,
    MinPlayer = 0,
    MaxPlayer = 0,
    MinXp = 0,
    MaxXp = 1000,
    Status = RoomStatus.Initial,
    IsTurnBasedGame = false,
    GameOrderType = GameOrderType.RoundRobin,
    Metadata = "any data",
    Players = null
});
```

### Join by AutoMatch[​](https://docs.dynamicpixels.dev/realtime/rooms#join-by-automatch) <a href="#join-by-automatch" id="join-by-automatch"></a>

Looking for a suitable room to join or create one

```csharp
var room = await ServiceHub.Services.MultiPlayer.RoomService.AutoMatch();
```

### Get all existing rooms[​](https://docs.dynamicpixels.dev/realtime/rooms#get-all-existing-rooms) <a href="#get-all-existing-rooms" id="get-all-existing-rooms"></a>

The function will return all available rooms to join

```csharp
var rooms = await ServiceHub.Services.MultiPlayer.RoomService.GetAllRooms(new GetAllRoomsParams
{
    Skip = 0,
    Take = 0
});
```

### Get all existing rooms Match user's XP[​](https://docs.dynamicpixels.dev/realtime/rooms#get-all-existing-rooms-match-users-xp) <a href="#get-all-existing-rooms-match-users-xp" id="get-all-existing-rooms-match-users-xp"></a>

The function will return all available rooms to join according to the user's xp

```csharp
var rooms = await ServiceHub.Services.MultiPlayer.RoomService.GetAllMatchedRooms(new GetAllRoomsParams
{
    Skip = 0,
    Take = 0
});
```

### Get Room By ID[​](https://docs.dynamicpixels.dev/realtime/rooms#get-room-by-id) <a href="#get-room-by-id" id="get-room-by-id"></a>

The function will return room's details by room's ID

```csharp
var room = await ServiceHub.Services.MultiPlayer.RoomService.GetRoomById(roomID);
```

### Get Room By Name[​](https://docs.dynamicpixels.dev/realtime/rooms#get-room-by-name) <a href="#get-room-by-name" id="get-room-by-name"></a>

The function will return room's details by room's name

```csharp
var room = await ServiceHub.Services.MultiPlayer.RoomService.GetRoomByName(roomName);
```

### Join[​](https://docs.dynamicpixels.dev/realtime/rooms#join) <a href="#join" id="join"></a>

Joining to a room by room's ID

```csharp
var room = await ServiceHub.Services.MultiPlayer.RoomService.Join(roomID);
```

### Leave[​](https://docs.dynamicpixels.dev/realtime/rooms#leave) <a href="#leave" id="leave"></a>

Leaving a room by room's ID

```csharp
await ServiceHub.Services.MultiPlayer.RoomService.Leave(roomID);
```

### Delete Room[​](https://docs.dynamicpixels.dev/realtime/rooms#delete-room) <a href="#delete-room" id="delete-room"></a>

Delete a room by it's ID

```csharp
await ServiceHub.Services.MultiPlayer.RoomService.DeleteRoom(roomID);
```

## Match Management

### Make Match[​](https://docs.dynamicpixels.dev/realtime/match#make-match) <a href="#make-match" id="make-match"></a>

Create a new Match

```csharp
var match = await ServiceHub.Services.MultiPlayer.MatchService.MakeMatch(roomId, lockRoom);
```

### Make and Start Match[​](https://docs.dynamicpixels.dev/realtime/match#make-and-start-match) <a href="#make-and-start-match" id="make-and-start-match"></a>

Create a new Match and start it

```csharp
var match = await ServiceHub.Services.MultiPlayer.MatchService.MakeAndStartMatch(roomId, lockRoom);
```

### Load Match[​](https://docs.dynamicpixels.dev/realtime/match#load-match) <a href="#load-match" id="load-match"></a>

Load a match by its ID

```csharp
var match = await ServiceHub.Services.MultiPlayer.MatchService.LoadMatch(matchId);
```

### GetMyMatches[​](https://docs.dynamicpixels.dev/realtime/match#getmymatches) <a href="#getmymatches" id="getmymatches"></a>

Get user's matches

```csharp
var matches = await ServiceHub.Services.MultiPlayer.MatchService.GetMyMatches();
```
