How to allocate a ViewID for a network manager? (PUN 2.7)

Options
Hi,

I have a PhotonNetworkManager MonoBehaviour with a few PunRPC functions. For the RPC to work I need a PhotonView. I'm adding the PhotonView at runtime (in OnEnable) because I want to keep my prefabs network API-agnostic.

I use AllocateSceneViewID() on the master client after creating a room and then send that ViewID to the other players (using RaiseEvent) so that their network manager has the same ID and RPC calls work.

This works fine, but only for the first room created. If I exit the room and create another one, AllocateSceneViewID() fails:
AllocateSceneViewID() can't be used for PhotonViews that already have a viewID. 
Is there a better way of handling this, or is the solution not to use RPCs and use events instead?

Thanks!

Comments

  • olistan
    Options
    I think I found a workaround: Add the PhotonView in OnJoinedRoom(), just before calling AllocateSceneViewID(), and destroy it in OnLeftRoom().

    I'll just need to synchronize the ViewID update correctly so the PhotonView exists when I try to update it... I'm thinking of using a custom room property instead of an event to transmit it now.
  • olistan
    Options
    Turns out it's better to use AllocateViewID() instead of AllocateSceneViewID() or there will be conflicts with the ViewID of scene objects.