Client unable to see other players in the same room. Master can however.

I've seen this question asked in a couple of places, and the answer usually seems to be "Make sure to use PhotonNetwork.LoadLevel" and "PhotonNetwork.AutomaticallySyncScene = true" as well as using Photon Network to instantiate. I am doing all of these however, I still cannot see players in the same scene (however objects instantiated after the client joins are visible).

The problem: As stated above, when multiple users are in a room, only the master client can see other players and instantiated objects. When the other clients finish loading, they can see the world and newly instantiated objects, but no players or old instantiated objects.

The process: When a player presses the "find game" button, they trigger PhotonNetwork.JoinRandomRoom(); and attempt to join a room or create one. A 10 second timer begins. A number of players can join during this 10 second period. After 10 seconds, the room is locked PhotonNetwork.CurrentRoom.IsOpen = false; and the game is loaded PhotonNetwork.LoadLevel(1);. The object persists, and if it's the master client, it spawns enough AIs to equal 10 (everything is instantiated using PhotonNetwork.Instantiate. In addition to spawning AIs, a number of guns are spawned by the MC. When the client's level finishes loading (usually a few seconds later), none of those objects or AIs are visible to the client. However, the objects they spawn (bullets, lasers, etc) appear to the client. The master client can see everything and everyone, including the newly joined clients, leading me to believe that there's some problem with joining players fetching the buffered players and objects created before they joined.

Are there any common mistakes that could lead to something like this?

I am using PUN V2 which I recently switched to, unsure if there's a problem related to that or not. I am also deploying to WebGL

Best Answer

  • dsprui11
    dsprui11
    Answer ✓
    Fo future people who'd like to reference this, my solution in the end was a combination of two of the proposed solutions. Basically, when the master client loads the new level, nothing is instantiated immediately, instead I start a 20 second timer (the maximum amount of time I'm willing to wait for slow connections). When a client successfully loads the level, they send an RPC to the master who then keeps track of the number of calls received vs the number of people in the room. Once the number matches, Players and items are spawned (this usually takes no more than 5 seconds)

Answers

  • Ok, I figured out part of the solution, perhaps someone from Photon could let me know what resources exist to rectify this. Basically, I spawn objects as soon as the master client enters the room however, the other clients haven't entered yet so the objects are spawned for them in the lobby scene. When they then transition to the scene they are loading, the objects are deleted.

    With this in mind, I know that a potential solution would be to add "don't destroy on load"s to each object and manage them based on the loaded scene. I'd prefer not to do this, as it's a tad sloppy and hackish. Also, depending on how long it takes for the user to load the level, a large queue of don't destroy objects would be built up. (This would also mean that almost all objects that are to be instantiated in the scene must be destroyed as you can't know how long it will take to load).

    Another potential solution would be to just add a time delay to the object instantiation. The problem with this is that load times vary, and I'd be stalling the game for other players while waiting.

    Does Photon have a built in way to lock instantiated objects to the scene? I know that because of the way this is phrased, "InstantiateSceneObject" would be the suggestion, however when I do that, the objects are still destroyed when loading a new scene.
  • dsprui11
    dsprui11
    Answer ✓
    Fo future people who'd like to reference this, my solution in the end was a combination of two of the proposed solutions. Basically, when the master client loads the new level, nothing is instantiated immediately, instead I start a 20 second timer (the maximum amount of time I'm willing to wait for slow connections). When a client successfully loads the level, they send an RPC to the master who then keeps track of the number of calls received vs the number of people in the room. Once the number matches, Players and items are spawned (this usually takes no more than 5 seconds)