Changing scene while joinin room and RPC buffer in Unity Photon Networking

I have a button to create and join a random room in my main menu. After the client joins (or creates and joins) a random room, i change the scene to game(main) scene in “OnJoinedRoom” function. It works well untill i use RPC call with buffers.

There are 5 spawn points in game scene, and everytime a player joins the room, it “occupys” a spawn point, so noone else can spawn at that point. So i have list of spawn points in my code, and everytime a player joins, it randomly picks a point from that list and “removes” it from the list, and does this by a RPC call so, whoever joins the game after, they remove that point too.

But there is a problem with that RPC’s buffer because of the “scene change” thing. As i said, i “join a room” and then “change the scene” when the “OnJoinedRoom” gets called. Because of this, RPC buffers are called just when the player joins the room, and before the scene change. And because the scene hasn’t changed yet, it troubles to find the buffered photonview. I throw outs an error, and doesn’t update that list.

Can i delay the buffer calls? Or how else should i change my scene while joining a room? What am i doing wrong?

There’s an easier way to change your scene while joining a room. Set up a custom room property when creating a room. This property can have any unique name. Then, in the OnJoinedRoom function, call this:

PhotonNetwork.LoadLevel(PhotonNetwork.room.customProperties["propertyName"].ToString());

What this does is it will load a level as a room, using the value of your custom property as the level name.

How the scene in the lobby is selected is sort on you to figure out, but what I did was I set up an array of strings and an index along with some GUI functions. Something like this:

GUILayout.BeginHorizontal();
                if (GUILayout.Button("<", GUILayout.Height(20)))
                {
                    mapIndex--;
                }
                if (mapIndex < 0)
                {
                    mapIndex = maps.Length - 1;
                }
                GUILayout.Label(selectedMap);
                if (GUILayout.Button(">", GUILayout.Height(20)))
                {
                    mapIndex++;
                }
                if (mapIndex > maps.Length - 1)
                {
                    mapIndex = 0;
                }

                selectedMap = maps[mapIndex];

                GUILayout.EndHorizontal();

When other players join your room, their clients will also be loaded into the same scene.

Hope this helps.