Search Unity

In Build, Awake of pre-placed networked object is called later than OnStartServer of player

Discussion in 'Multiplayer' started by moco2k, Aug 13, 2016.

  1. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Hey,

    I have encountered a strange issue with UNET which I do not understand. Maybe it is even a bug.

    Game Setup:

    - The game is set up using offline and online scene. Test is run in Host mode.
    - There is a singleton GameManager object which is pre-placed in the online scene. This object uses the Awake function to set up an instance reference (usual singleton pattern).
    - Then, there is a usual networked player object. This uses the OnStartServer hook. Within this hook, the global GameManager instance is accessed.

    When I run the game within the Unity editor, everything works fine and as expected. The GameManager Awake is called first and the instance is set ready. Sometime later, the OnStartServer hook of the player object is called and it is able to properly access the GameManager instance.

    However, when I run the compiled game build, I encounter the issue that the GameManager Awake function is called very late so that it is actually called AFTER the player object OnStartServer function hook. In fact, the order of function callbacks in the output_log of the build is completely different to the order within Unity. Finally, this leads into a NULL reference exception because the GameManager instance is not ready upon the OnStartServer call.

    I would have expected that Awake is always called first. Do I have missed something?

    Also, it is very strange that the callback order is different between the Unity editor and the game build. Is this normal or is it possible that there is a problem somewhere else which causes this behavior?

    Any help is much appreciated.
     
  2. AntonioCiolino

    AntonioCiolino

    Joined:
    Nov 28, 2016
    Posts:
    1
    Was this ever resolved? I am facing the same thing with the same scenario.
     
  3. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    The UNET staff had been informed about this and as far as I know it also had been registered as a bug report. However, Alex told me that it is not trivial to fix and requires considerable redesign. The recent patch notes did not include any information on this. I doubt that it has been fixed yet.
     
  4. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    yes it is right. I reopened the bug and ask to add proper documentation...