Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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.