Issues When Adding PhotonViews to GameObjects at Runtime


I am working on a game where I need to be able to add and remove PhotonViews to objects at runtime relatively frequently. I have a system where I add a PhotonView on the client side, then send the name of the GameObject, and the ViewID that I allocated to the PhotonView through a custom PhotonView (lets just call it SharedInfo) script that I have created. SharedInfo then sends the data over the network to itself (serializes it? I'm not sure what the technical term is for this). It uses the name that is sent over the network to find the corrosponding GameObject and creates a PhotonView on that object, with a ViewID that is the same as the one sent over the network. Sorry if I explained this poorly.

Anyways, when the master client runs this, everything works fine. But the weird thing is that when a non-master client runs this, I get the following warning.

Received OnSerialization for view ID XXXX. We have no such PhotonView! Ignored this if you're leaving a room. State: Joined

What is weird is that the warning doesn't appear at all on the non-master clients. It only appears on the master client when a non-master client tries to run through this "process". What I also find strange is that it seems to be stopping SharedInfo from reading anything from the stream on the master client (as I found out by putting a debug.log in the start of if (stream.isreading), and seeing that the debug.log never showed up in the console).

Again, I'm sorry if this is explained poorly. But does anybody have any ideas as to why this might be happening?


  • After a bit more testing, I discovered that the warning does appear on non-master clients if another non-master client is what runs the process. Furthermore, if i don't ever add anything into the observed components of the PhotonView that I create at runtime, the warning goes away. In other words, the warnings only appear when there is something in the observed components.
  • Hi @Stekon,

    Sorry for the long delay!

    In order to be synchronized over the network, PUN requires GameObject with PhotonView components to be created using one of the following 4 methods:

    - PhotonNetwork.Instantiate
    - PhotonNetwork.InstantiateSceneObject
    - GameObject with PhotonView already in the scene
    - Manual instantiation

    If you want to sync. a GameObject with PhotonView dynamically added at runtime, it's not recommended and could be a lot of trouble.
    Unless the use case really requires this, use one of the methods supported out of the box.
Sign In or Register to comment.