Search Unity

OnCheckObserver Timing

Discussion in 'Multiplayer' started by ObliviousHarmony, Jul 7, 2015.

  1. ObliviousHarmony

    ObliviousHarmony

    Joined:
    Jul 3, 2014
    Posts:
    79
    Hello,

    I'm currently working on an alternative scoping system for my game, and I've run into a small snag. "OnCheckObserver" seems to be called after the 'MsgType.Connect' message, rather than after the 'MsgType.AddPlayer' message. This makes it a little more difficult to check for things like positional data, as the player object hasn't been created yet. The work around that I'm going to employ will be to create the player in 'Connect' and then add them to the connection and bring them to life in 'AddPlayer'.

    Is there any issues with this method that I should watch out for?
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    yeah there are some timing issues here. The observer list is per-connection, not per player, and is initialized when the connection becomes ready, regardless of whether a player exists at the time or not. There is bug filed on this internally.

    So OnCheckObserver fails most of the time. If the other objects are calling RebuildObservers() on a timer, things will work themselves out over time though. But objects would "pop" in for the player randomly/incrementally instead of all at once.
     
  3. Bladesfist

    Bladesfist

    Joined:
    Jan 3, 2012
    Posts:
    107
    I also filed a docs bug report for all of the NetworkBehaviour events as the execution order is not explained anywhere. Some (possibly all) are called before Start() which means that you must use awake for any initialization.