Create Room
Overview
Creates a new room and automatically joins the room as its room owner.
Methods
Called by players to begin an asynchronous operation to create a room and using the specified wantRT, and PlayerLimit.
Called by players to begin an asynchronous operation to create a room and using the specified string room custom data, wantRT, and PlayerLimit.
Called by players to begin an asynchronous operation to create a room and using the specified serializable object room custom data, wantRT, and PlayerLimit.
Called by players to begin an asynchronous operation to create a room and using the specified string room custom data, wantRT, PlayerLimit, and index data.
Called by players to begin an asynchronous operation to create a room and using the specified serializable object room custom data, wantRT, PlayerLimit, and index data.
Called by players to begin an asynchronous operation to create a room and using the specified string room custom data, wantRT, PlayerLimit, PlayerTimeToLive, isPrivate, and index data.
Called by players to begin an asynchronous operation to create a room and using the specified serializable object room custom data, wantRT, PlayerLimit, PlayerTimeToLive, isPrivate, and index data.
Class
The index data object of a room.
The error that occurred when a lobby API operation failed.
Maximum size of a room custom data is 5KB.

Examples

In this example, we created a room with serializable object as its custom data. The custom room data has two teams and we assigned the local player to team1.
1
// Serializable classes for room custom data
2
[Serializable]
3
public class RoomCustomData {
4
public string name;
5
public TeamCustomData team1;
6
public TeamCustomData team2;
7
}
8
9
[Serializable]
10
public class TeamCustomData {
11
public List < string > players = new List < string > ();
12
}
Copied!
1
// Create a new RoomCustomData object;
2
RoomCustomData roomData = new RoomCustomData();
3
4
// Set its name to "New Room"
5
roomData.name = "New Room";
6
7
// Create two TeamCustomData objects
8
// Assign them to team1 and team2 of the RoomCustomData object
9
roomData.team1 = new TeamCustomData();
10
roomData.team2 = new TeamCustomData();
11
12
// Assign local player to team1 by
13
// adding local player's PlayerId to the players list of team1
14
roomData.team1.players.Add(NetworkClient.Lobby.PlayerId);
15
16
// create a new room with the RoomCustomData serializable object
17
NetworkClient.Lobby.CreateRoom(roomData, true, 4, (successful, roomId, error) =>{
18
if (successful) {
19
Debug.Log("Room created " + roomId);
20
}
21
else {
22
Debug.Log("Failed to create room " + error);
23
}
24
});
Copied!
Copy link
Contents
Examples