CustomRoomPropertiesForLobby is not working

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

CustomRoomPropertiesForLobby is not working

AT1LLA
2017-02-19 10:36:04

Here is how i create my room:

public void CreateRoom(){  
        LobbyOptions = new string[2];  
        LobbyOptions[0] = MapIndex;  
        LobbyOptions[1] = GameModeIndex;  
        

        RoomOptions roomOptions = new RoomOptions();  
        roomOptions.IsVisible = true;  
        roomOptions.IsOpen = true;  
        roomOptions.MaxPlayers = (byte)MaxPlayersIndex;  
        roomOptions.CustomRoomPropertiesForLobby = LobbyOptions;

        PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);  
}

Here is how I get my rooms:

public override void OnReceivedRoomListUpdate()  
    {  
        Debug.Log("GET ROOMS: " + PhotonNetwork.GetRoomList().Length);

        foreach (RoomJoiner roomButton in rooms)  
        {  
            Destroy(roomButton.gameObject);  
        }  
        rooms.Clear();  
        int i = 0;  
        foreach (RoomInfo room in PhotonNetwork.GetRoomList())  
        {  
            if (!room.open)  
                continue;  
            GameObject roomButton = Instantiate(roomButtonPrefab);  
            roomButton.GetComponent().RoomName = room.name;  
            string info = room.name.Trim() + " (" + room.playerCount + "/" + room.maxPlayers + ")";  
            Debug.Log(info);  
            Debug.Log("room.CustomProperties.Count " + room.CustomProperties.Count);  
            roomButton.GetComponentInChildren().text = info;  
            rooms.Add(roomButton.GetComponent());  
            roomButton.transform.SetParent(ServerListPanel, false);  
            roomButton.transform.position.Set(0, i * 120, 0);  
        }  
}

CONSOLE
room.CustomProperties.Count 0

Am I doing something wrong? Thanks.

Comments

JohnTube
2017-02-20 10:06:45

Hi @AT1LLA,

Thank you for choosing Photon!

Please try setting values to those custom room properties when creating the room.

ExitGames.Client.Photon.Hashtable roomSettings = new ExitGames.Client.Photon.Hashtable() {  
		{ MapIndex, mapIndex }, { GameModeIndex, gameModeIndex }  
	};  
roomOptions.CustomRoomProperties = roomSettings;

AT1LLA
2017-02-20 17:45:44

Hi @JohnTube ,
Sorry I didn't explained myself. I want to create a lobby. I will have some string variables like GameMode and Map. I want to show them in lobby. I tried your script but it didnt work. I tried
roomOptions.CustomRoomProperties = new string[] { "1", "2", "3" };
just to test but it alse didnt work. I think my problem is hov i get the values.
I do
Debug.Log("room.CustomProperties.Count " + room.CustomProperties.Count);
as the sctipt i posted. Thank you for your answer.

JohnTube
2017-02-21 15:12:02

Did you try merging my suggestion with your code?
Room properties are key/values where keys are strings.
Something like this:

public void CreateRoom(){  
        LobbyOptions = new string[2];  
        LobbyOptions[0] = MapIndexKey;  
        LobbyOptions[1] = GameModeIndexKey;  
        ExitGames.Client.Photon.Hashtable customProperties = new ExitGames.Client.Photon.Hashtable() {  
		{ MapIndexKey, mapIndexValue }, { GameModeIndexKey, gameModeIndexValue }  
	};  
        RoomOptions roomOptions = new RoomOptions();  
        roomOptions.IsVisible = true;  
        roomOptions.IsOpen = true;  
        roomOptions.MaxPlayers = (byte)MaxPlayersIndex;  
        roomOptions.CustomRoomPropertiesForLobby = LobbyOptions;  
        roomOptions.CustomRoomProperties = customProperties;  
        PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default);  
}

AT1LLA
2017-02-21 17:06:51

Oh, I did it thank you :smile:

Back to top