Instantiate once or each time you enter a new room?

Options
After connecting to Photon and instantiating your local player, are you required to instantiate it for after each new scene/map load? If you don't destroy it on load, will it show up for the remotely connected players like it does when you instantiate each time?

In PUN Player Instantiation docs https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/player-instantiation, "Keeping track of the player instance":
It suggests that you may need to only instantiate once for each game play, but the code comment mentions surviving a level synchronization. So, does this only work, if you have a group of players that are staying together with level sync?

Comments

  • Hi @flyingaudio,

    if you mark a Game Object as DontDestroyOnLoad this object won't get destroyed automatically any longer, means that it will persist scene loading until it gets destroyed by code, for example by using PhotonNetwork.Destroy(...).

    In the Basics Tutorial example, the level is adjusted accordingly to the number of players in the room and the player's object persists scene loading.

    So, does this only work, if you have a group of players that are staying together with level sync?


    Basically yes, but the reason might be another one than you are thinking about: If you have a networked object, this object is available on all clients by default and furthermore gets synchronized on all clients as well. If you have for example two groups of two players each and both groups have loaded different levels, all clients will instantiate (and synchronize) each Game Object of each client. As a result, players might encounter other players, that "shouldn't be there" (clipping through walls or the terrain, etc.).

    There would be a possibility to work around this by using Interest Groups, but this would be an entirely other topic.

    To come back to your original question: as long as all clients are loading the same scene, you can mark their objects as DontDestroyOnLoad. If you have multiple clients who loaded different scenes, you should separate either their objects (by using Interest Groups) or the clients themselves (by letting them join different rooms).