duplicate PhotonView ID problems when using PhotonNetwork.InstantiateRoomObject

I have some objects in my project that need to persist across scene loads and remain throught the entire experience. They get instantiated by the MasterClient and Unity's DontDestroyOnLoad gets called on their GameObject so that they can persist between scenes.

Previously I was using PhotonNetwork.Instantiate to create them, but I realized that if the MasterClient ever gets disconnected, these objects will get destroyed and I learned about PhotonNetwork.InstantiateRoomObject, which seems like it is well-suited to my use-case.

However, I've noticed that since making that switch from PhotonNetwork.Instantiate to PhotonNetwork.InstantiateRoomObject, the PhotonView ID's are now in a range that conflicts with Scene objects that have PhotonViews on them. When I was using PhotonNetwork.Instantiate, the PhotonView IDs would start at 1001 and go up from there. Now with PhotonNetwork.InstantiateRoomObject, the PhotonView IDs are in the 1-999 range which is ripe for conflicting with SceneObjects. So when a scene loads and there is a duplicate PhotonView ID, Photon decides to delete my object that was created with PhotonNetwork.InstantiateRoomObject.

How can I have my instantiated objects get View IDs that won't conflict with scene objects? It seems to me that InstantiateRoomObject should give View IDs in the 1000 range just like Instantiate...

Using PUN 2 v2.41 with Unity 2020.3.42


  • Scene- or Room-Objects use the range 0-999.

    Networked objects in the scene need a fixed value, so everyone knows which object is referred to. They just load and don't sync over the network.

    So, you could load your scene first. Then PUN should know the used values and pick another.

    Alternatively, you could define the lowest viewID to use in each scene by using the SceneSettings. You can define a start value per scene.

    If you need something more sophisticated, you could come up with your own, Manual Instantiation.

  • Hi Tobias, it sounds like defining the lowest viewID using SceneSettings would be a good solution for this project. Can you point me to where I'd find these SceneSettings? When I google "Photon SceneSettings" the only partially relevant result seems to be for Fusion (I'm using PUN2).

  • They are part of your project. PUN will generate the PunSceneSettings.