Search Unity

Scripts execution order in Unity 5 Networking

Discussion in 'Multiplayer' started by ownself, Nov 14, 2016.

  1. ownself

    ownself

    Joined:
    Mar 18, 2013
    Posts:
    16
    I just started to work with new unity networking system in Unity5. Today I found out a weird thing that I couldn't understand.
    I make 2 new scripts and add "Debug.Log" into Start() and Update(), both of them, then disable the game object with 2 scripts added as components, once the game started, I enable the game object, check the console window, everything looks normal.

    Then if I add NetworkManager game object and add "NetworkIdentity" to previous logging game object, start the game, host the game, the logging game object will be automatically enabled, then you will see this at console window.

    It seems Start() and Update() functions are not according what they should be, did I misunderstanding any about Unity Networking??

    ---------------------------------------

    Also I tried "Awake()" for testing, then more weird things happened. A gameobject with "NetworkIdentity" will call its "Awake" right after game started Editor Mode, then call "Start", "Update" once you StartHost(), but once you make a standalone build, "Awake" will be call after StartHost() but not at the beginning of the game. This leads me more confused. :(

    Test based on 5.4.0f3
     
  2. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Please also check out this thread. Chances are that this is the same or at least a related issue.

    In my project, I have also encountered the problem that networked callbacks like OnStartServer and OnStartLocalPlayer on player objects are called before Awake functions of networked objects which are pre-placed in the scene. However, this is only the case in standalone builds but not in the editor. So, this seems like a strong indicator that we have some kind of bug here.

    I had submitted a QA case, but so far the QA was not able to reproduce this issue. It seems that they need an example project for reproduction. Unfortunately, I cannot submit my actual game project for reasonable reproduction as it is because it's multiple of GB and quite complex. So, I have planned to create a clean and small project for reproduction of this issue. However, unfortunately, I did not found the time yet to do this.

    Maybe you can chime in on this as well and also raise a bug ticket. In case that you maybe have a smaller project, maybe you can even provide it to Unity QA so that they can reproduce the issue. We really need to get this fixed, or, at least, we need to understand what is going on here.
     
    Last edited: Nov 14, 2016
  3. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    i hate to dig up this old thread, but does anyone know if this ever got fixed?

    i just noticed i have a similar bug in standalone only where Start on a non-networked object incorrectly is getting called before Awake on a networked object. works correctly in Editor. pretty gross.

    i'm on Unity 5.3.7 so pretty out of date. maybe it was fixed in a recent version?

    the weird thing, is that i'm pretty sure this hasn't been an issue with these two gameobjects until fairly recently. perhaps something in my project is trashed after having worked on it for so long?
     
  4. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    FYI Scene based game objects with a Network Identity component on them are _automatically_ disabled by the Network system, until they get a SpawnObjects() call, which the NetworkManager does automatically for you. However, the timing of these calls will not be the same for any other non-Network Identity objects in the scene.
     
  5. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    ok, so the idea then is that they're disabled before awake is called, then later re-enabled, thus finally triggering Awake on it after Start has been called on non-networked objects? i can buy that if that's the case.

    is there much overhead in giving my non-networked object a NetworkIdentity component? in terms of added bandwidth, i mean. assuming that it isn't going to be doing any message sending at all....just looking to keep it in sync with the other networked objects in terms of script execution order