Search Unity

When Awake() will be call for game object with NetworkIdentity??

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

  1. ownself

    ownself

    Joined:
    Mar 18, 2013
    Posts:
    16
    I found a very weird issue with Unity 5 Networking, that is a script attached to a gameobject which also has a NetworkIdentity component.

    then in Editor mode:
    script's Awake() will be called after you start the play mode, not need to StartHost() or StartServer()

    in Standalone build:
    script's Awake() will NOT be called after App launched, only will be called after StartHost() or StartServer()

    Bug??? or it's just what they designed this way..... #$@$!#$@%%#%

    I read some of UNet source code, found such comments.... scared me a little.... they don't know what they are doing either.

    wdtm.png
     
  2. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    There are some more threads already which relate to this issue:

    https://forum.unity3d.com/threads/scripts-execution-order-in-unity-5-networking.440973/
    https://forum.unity3d.com/threads/onstartclient-called-before-scene-is-fully-loaded.427952/

    aabramychev from UNET team knows about this and I think this issue already has been recognized as a bug. I hope that they fix it soon. As long as this is not fixed, I have suggested to add information to the documentation about the different callback times between Editor and Build.
     
    Last edited: Nov 18, 2016
  3. ownself

    ownself

    Joined:
    Mar 18, 2013
    Posts:
    16
    Good to know, hope they can fix it soon, thank you, UNet seems far away to be something we would use.
     
  4. Deleted User

    Deleted User

    Guest

    We're on Unity 2017.3.0f3 already and the Awake issue still exists. has there any bug report been issued?
     
  5. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109

    I just found this thread, been trying to figure it out for days as to why my networked game is working fine when the Host is the Editor but not if i run it using builds as the host.

    All i really need to do right now is make sure my NetworkBehaviour scripts are set to DontDestroyOnLoad, because when it changes scene from offline to online it fails unless I use it from within Editor as host (and then for some reason Awake gets called!!!) . Is there any way around this that people know of?

    thanks
     
  6. megabrobro

    megabrobro

    Joined:
    Jul 8, 2017
    Posts:
    109
    After much messing about with my code trying to overcome this problem, I noticed that my NetworkBehaviour scripts (in my case MatchdayManager.cs) which is responsible for spawning the football, amongst other things later was always set to INACTIVE as soon as my game loaded (even though I never set this to happen anywhere , it must just be because its a networkbehaviour script!?!??!)

    So I went about making sure it is never INACTIVE and the only way I managed to get the game working was to put a call in my GameManager : Monobehaviour script, I made Update loop there specially for this and every frame I set the MatchdayManager.SetActive(true).

    I have posted it as an answer here : https://gamedev.stackexchange.com/q...nity-multiplayer-networked-game/159878#159878

    And hopefully people from here, or stackexchange can shed light as to what is wrong (ie. is it my code, or Unity) and what we can do to workaround or fix this . Would also be great if Unity developers could comment on this matter. Thanks