How to get pre-existing game objects to load on scene switch

Options

Three game objects start in a different scene and persist into another scene.

One of those game objects is supposed to be a player. I know you would normally use PhotonNetwork.Instantiate, but is there a way to keep the player in the scene and still have them appear for other users? The same goes for the other two objects, not players but persistent objects that move between scenes.

I would have done the instantiate method, but many references between the prefabs need to be maintained, which would make switching to instantiation very tedious.

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    Options

    Objects in the scene can be networked too. Put a PhotonView on it and the Master Client will have control.

    You need to make sure the scene networked object is known to every player (so likely you have to load this scene first for anyone) and you have to make sure no other scene is having a networked object with the same viewID (else that clashes).

    To keep objects from being destroyed on scene load, use DontDestroyOnLoad on them.

    Disclaimer: I think this is a tricky approach and could go wrong in a lot of ways. Aside from general advice, I can't really help much because we never implemented things this way. It'd doable but be prepared to experiment. I'd use a set of prototyping scenes, which just have the bare minimum of stuff to make this work first. It will be frustrating to start with assumptions and a project that doesn't do what you planned.

Answers

  • Tobias
    Tobias admin
    Answer ✓
    Options

    Objects in the scene can be networked too. Put a PhotonView on it and the Master Client will have control.

    You need to make sure the scene networked object is known to every player (so likely you have to load this scene first for anyone) and you have to make sure no other scene is having a networked object with the same viewID (else that clashes).

    To keep objects from being destroyed on scene load, use DontDestroyOnLoad on them.

    Disclaimer: I think this is a tricky approach and could go wrong in a lot of ways. Aside from general advice, I can't really help much because we never implemented things this way. It'd doable but be prepared to experiment. I'd use a set of prototyping scenes, which just have the bare minimum of stuff to make this work first. It will be frustrating to start with assumptions and a project that doesn't do what you planned.