Event oder not respected

Good day,

I'm currently working on porting my game to Photon Cloud, up so far it's going well except on important detail. And yeah, sorry for the long post but I rather write more than being vague ;)

Correct me if I'm wrong, but with Unity3d standard networking all the events are queued in the same queue as RPC calls. With Photon it seems that this order is not respected from my results.

However from what I'm observing event aren't played back in the same exact order.

When a new player join the Room, the MasterClient will network instantiate my PlayerPrefab. The PlayerScript is basically managing points, health, lifes etc. After instantiating the PlayerPrefab I call an SetPlayer RPC to associate the PhotonPlayer to the game object.

When the PlayerPrefab is matched with the PhotonPlayer, the PhotonPlayer will network instantiate a second the UnitPrefab. So the MasterClient owns the PlayerPrefab instance while the Client owns the UnitPrefab. That way, the Client sends position and action updates of it's unit while the MasterClient will make sure that all the important stats are uniquely handled to prevent inconsistant stuff.

Finally, when the UnitPrefab is instantiated I'm hooking on the OnPhotonInstantiate callback to find the PlayerPrefab instance that instantiated the UnitPrefab. That way the UnitPrefab instance can be nested by it's PlayerPrefab instance in the SceneHiearchy.

The problem I'm observing is that the event order is not respected when a Client tries to join an existing Room.

Expected order:
    - Join Room - Receive PlayerPrefab instance (associated with MasterClient) - Receive SetPlayer RPC on PlayerScript - Receive Unit instance (owned by MasterClient) => OnPhotonInstantiate callback - Receive PlayerPrefab instance (associated with local Client) - Receive SetPlayer RPC on PlayerScript - Network instantiate and send UnitPrefab (owned by local Client) => OnPhotonInstantiate callback

Observed order:
    - Join Room - Receive PlayerPrefab instance (associated with MasterClient) -
Receive Unit instance (owned by MasterClient) => OnPhotonInstantiate callback
- Receive SetPlayer RPC on PlayerScript

- ...


I'd like to know it what I'm observing is the expected behaviour of Photon and if you guys found work arounds for such situations. The basic work around I may think of is delaying the callback of OnPhotonInstantiate to next frame by using a coroutine but it's kinda dirty and has side effects in my game.

Thanks!

Comments

  • The order of events (RPCs, Instantiates) should be exactly as it arrived on the server in the room. Photon is caching those buffered actions for Unity and sends them (in order) to new players on join, before any "live" events (anything that's going on now but not being buffered).
    It must be some timing issue that is slightly different for Photon than for Unity.
    - Receive PlayerPrefab instance (associated with MasterClient)
    - Receive SetPlayer RPC on PlayerScript
    - Receive Unit instance (owned by MasterClient) => OnPhotonInstantiate callback

    If this is sent by one client one after the other, then the order should be the same for joining players.
    When a new player join the Room, the MasterClient will network instantiate my PlayerPrefab. [...] After instantiating the PlayerPrefab I call an SetPlayer RPC to associate the PhotonPlayer to the game object.

    Who is "I" in this case? Is the master doing all those actions?
  • While I was woking on creating a repository and a trimmed project to show case my issue I haven't been able to reproduce the issue. I'll try to figure ou what's the difference between my show case project and the real one.
    Tobias wrote:
    Who is "I" in this case? Is the master doing all those actions?
    Yes, the PlayerPrefab is instantiated by the MasterClient and SetPlayer (buffered) RPC is called by the MasterClient as well.