PhotonNetwork.CurrentRoom.CustomProperties collection is empty

I'm trying to nail down what could be causing an issue for a dev friend. He makes a call to PhotonNetwork.CreateRoom(randomRoomName, roomOptions); passing along some options and a room properties Hashtable with a "key" and "type". That should in turn call OnCreatedRoom() nothing is being done there but to log it and then OnJoinedRoom().

There is an if test at the top of OnJoinedRoom

if (PhotonNetwork.CurrentRoom.CustomProperties.ContainsKey(MultiplayerVRConstants.MAP_TYPE_KEY))

The collection however is empty. With (virtually) identical code my app works all the time. Any idea what may be causing this?


  • That sounds as if it should work.

    Which PUN version is used in that case?

  • tleylan
    tleylan ✭✭

    Hi Tobias... yes, we all expected it to work since we are all using the same code base. It is from an online course and one person reported getting an error.

    A bit of debugging revealed that the collection is empty despite that callback being the result of actually joining a room.

  • Tobias
    Tobias admin
    edited May 2022

    Make sure it's the same room. Maybe the room was full, JoinRandom failed and a new room was created (without setting the props)?! Was it the same room on the same server?

    Hard to say without more details. Does this reproduce?

  • tleylan
    tleylan ✭✭

    I'm confused. The project is a common project from a course that uses PUN.

    The guy is testing it and creates and joins a room. That function initiates 2 callbacks (it is the hands of PUN at that point). Are you suggesting one might create a room, join it and then the callback sends information from another server and another room? How would that be useful to anyone and importantly why doesn't it happen to anyone else (including me)?

  • tleylan
    tleylan ✭✭

    re: Hard to say without more details. Does this reproduce?

    It reproduces for him every time he tries. It never fails for me. We have nominally the same code, as I mentioned we took a course. I tend to refactor my code and sure he may have introduced a bug but the amount of code that could hide a bug is slim. There is a call to CreateRoom and a callback.

    In any case I don't know what it could be. Thanks.

  • Are you suggesting one might create a room, join it and then the callback sends information from another server and another room?

    No, this is not what I mean. I meant: If one client accidentally ends up in another room (in another region or so), then it likely has no properties you'd expect otherwise.

    Rooms are always fully distinct and we never send info from one to another. The client which always fails may be using a different region.

    Check the Matchmaking Checklist to verify each of the relevant values.

  • tleylan
    tleylan ✭✭

    Appreciate all the info and that you are trying to help. I don't get it though. This is one person running his app and there is no room so it creates a room and it logs that and that the player joined. It logs the callbacks but when it checks to make sure CustomProperties contains the name of the room "he just added" it has an empty collection.

    I don't think I am going to understand it. What other world, room or game might he be playing?

    So let me ask, could he have set "use the best choice" on what region to use rather than selecting an given region? I am trying to find what could be different (probably not in the code) that would make his version behave differently from every other person who entered the code from the course.

    I will try to read the docs but I also don't understand how a player can create room, join it and then find they are in some other region (or something) :-)

    I'm not arguing I am only saying there is only one player involved here and he can't enter his own room.


  • I misunderstood the posts above then. My impression was that the test is that several clients joined the same room but one didn't get the properties everyone else sees.

    Ok, so the situation is: The tutorial code shows how to set properties when creating a room. Some user of said code has the unexpected result that the properties are not set (despite that working in other cases).

    Yes, then my input didn't make sense.

    There is no known issue for that, so I can only point out things to try: Update Unity to the latest LTS version of the "yearly edition" you use.

    It could be a Custom Type which wasn't registered (due to missing this part of the tutorial, disabling some code or other).

    I think there was a version of Unity, which had issues with initializing properties and or Hashtables when you instantiate them. This was long ago but I'd verify that the Operation call contains all values and then check if the Result also has the needed values. Before the LoadBalancingClient calls SendOperation, you could Debug.Log the operation's content with .ToStringFull(). Also log ToStringFull for the OperationResponse in OnOpResponse. Check the content for your key values.

    It would help if I could get a zip of said code. I guess up to this point, it's a slim project. Zip and upload for us to fetch it and mail a link to: [email protected]

  • tleylan
    tleylan ✭✭
     private void CreateAndJoinRoom()
            String randomRoomName = $"Room_{mapType}{UnityEngine.Random.Range(0, 10000)}";
            String[] roomPropertiesForLobby = { MultiplayerVRConstants.MAP_TYPE_KEY };
            var roomProperties = new ExitGames.Client.Photon.Hashtable() { { MultiplayerVRConstants.MAP_TYPE_KEY, mapType } };
            var roomOptions = new RoomOptions();
            roomOptions.MaxPlayers = 20;
            roomOptions.CustomRoomPropertiesForLobby = roomPropertiesForLobby;
            roomOptions.CustomRoomProperties = roomProperties;
            PhotonNetwork.CreateRoom(randomRoomName, roomOptions);
  • tleylan
    tleylan ✭✭

    The Hashtable used is from Photon. I don't know the details for the versions being used but it is an online course and we all followed it and I believe we all used the latest LTS version. In any case I don't think we're going to discover what happened.

    Very nice of you offering to review the code but as I mentioned it isn't my project and my copy works fine.

    I'll check with the person and see what's up. He was going to key in all the code again. I suggested that he keep a copy of the non-working one so we can compare them afterwards.

    Thanks for you help.

  • Hi, im the one with the rogue proyect not working as intended. Sure, i will send it to you right away

  • The code looks correct and should not fail at all. So .. I am puzzled.

    Keep in mind that you can't all join the room when everyone is calling CreateRoom() of course. So one user will actually create the room, the others join.

    We'll see.

    Thanks for trying to debug this.

  • tleylan
    tleylan ✭✭

    I've long thought that it wouldn't be the code. We're following an online course. I suspected his Photon project was set up incorrectly or bugged or something. Possibly it was due to his Internet connection or provider but that is getting far less likely.

    I would recommend before running through the course again you set up a class (or two) that just exercises the connection methods to the PUN server. Just have buttons (or something) that connects, tests if a room exists, creates a room, joins a room, etc. Try to eliminate all the assets and functionality that isn't related so you have less to look at.

    I would also test one more time with the completed course material. If you obtain a project ID for that and that fails then it surely not the code.