Illegal view ID with DontDestroyOnLoad

Options
The code works like this:

1) Menu scene is loaded and there is a script Level.cs.
2) In its awake, if a "Master" object does not exist then it is instantiated (not Photon.Instantiate()).

Master object contains all kinds of objects such as the network manager and more items with Photon views.

3) If a map is selected and loaded, the master object is persisted since it has the DontDestroyOnLoad.

However, sending any RPC's, using photonviews from previous scene (the menu scene, photonviews under master objects) results in an error "Illegal view ID:0 method: *methodname* *gameobject name*

How to solve this?

Comments

  • Frosty
    Options
    I managed to solve this by changing the faulty photonView's id from 0 to 1 (photonView.viewId = 1). Why to 1? Because when I added the object to scene without instantiation, but in editor, then it set the view's id to 1.

    Why does this solve the problem? What if I have other photonViews that require changing the id the same way? Isn't there a better option for doing this?
  • Hi @Frosty,

    [...] photonviews under master objects [...]


    This is because the object doesn't exist on the other clients since you don't have called PhotonNetwork.Instantiate(...) for instantiating this game object.

    It is the same for 'photonviews from previous scene'. If they aren't marked as 'DontDestroyOnLoad' they get destroyed on scene loading.

    How to solve this?


    It seems you are looking for RaiseEvent which is independent from PhotonView components. How it works and how to use it is described in the RPCs and RaiseEvent guide.
  • Frosty
    Options
    This is because the object doesn't exist on the other clients since you don't have called PhotonNetwork.Instantiate(...) for instantiating this game object.


    So what's the difference between me calling Instantiate() on an object when the scene is loaded, versus just having the object there in the scene by placing it in unity's editor? And then after either of these loading a new scene...