Search Unity

UNET Scene Objects not Spawning w/ Custom NetworkManager

Discussion in 'UNet' started by Zullar, Nov 21, 2015.

  1. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    5.2.2f1
    TLDR
    Don't EVER call Awake() in a custom NetworkManager!


    So after a lot of testing I think I finally tracked down the source of my problems. If you have a custom Network Manager that inherits from NetworkManager it appears to override NetworkManager's base initialization if you call your own initialization during Awake(). This causes things like the NetworkManager.singleton not to be set, and also causes SceneObjects not to be "spawned" when a scene is loaded. Calling Awake() in a NetworkManager child doesn't cause any warnings and the NetworkManager.Awake() method is not protected/public so it can't be called by the child... so this means you can't use Awake(). This post is just a heads up for anybody having the problem (it took me a long time to track it down!).

    Here's example code that appears ruin the NetworkManager.

    Code (csharp):
    1.  
    2. public class TestNetworkManager : NetworkManager
    3. {
    4.     private void Awake()
    5.     {
    6.         //This causes NetworkManager.Awake() not to be called, and doesn't initialize properly causing very strange behaviors...
    7.     }
    8. }
    9.  
    Keywords
    Inherit NetworkManager scene object not spawned enabled disabled singleton Awake initialize
     
    Last edited: Nov 23, 2015
    Jodon likes this.
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    Edit: It appears calling Awake() causes 3 bugs.
    -NetworkManager.singleton not being set
    -SceneObjects not spawning (NetworkServer.SpawnObjects() isn't automatically called)
    -NetworkServer.OnServerSceneChanged() does not get called
     
    Jodon likes this.
  3. Jodon

    Jodon

    Joined:
    Sep 12, 2010
    Posts:
    434
    Please submit this bug, I believe I ran into this on the weekend and it's been causing me huge headaches! Nice find!
     
  4. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    HentaiHades and Jodon like this.
  5. Yodzilla

    Yodzilla

    Joined:
    Mar 21, 2013
    Posts:
    48
    Argh I'm on 5.2.3 and just hit this. Thanks!
     
  6. fabian-mkv

    fabian-mkv

    Joined:
    Nov 14, 2015
    Posts:
    13
    Ran into the same problem in 5.3.4
     
  7. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    I have custom network manager but i didn't use Awake event in my custom class but still getting the problem that my network identity object are disabled. Can anyone help?
     
  8. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    I made my custom network manager but i did n't use or call awake event but still i am getting the problem that my additive scene loaded object are disable. The loaded scene object contains network identity. why i am getting this problem?
     
  9. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,190
    @MFKJ u fixed this problem yet? ..i also have it now.
     
  10. qqquantum

    qqquantum

    Joined:
    Sep 22, 2015
    Posts:
    6
    I found out the hard way that if you do a
    Code (CSharp):
    1. public override void OnServerConnect(NetworkConnection conn)
    2. {
    3. //your code
    4. }
    The player prefaf is also not spawned. This does not apply to OnStartHost, OnStartClient, OnClientDisconnect, OnServerConnect or OnServerDisconnect. Only OnServerConnect. Weird.
     
  11. VirtualPierogi

    VirtualPierogi

    Joined:
    Sep 3, 2012
    Posts:
    54
    2018.1.9f2 the bug still exist
    funny aint it?
     
  12. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    UNET seems more or less abandoned at this point. I've moved over to Steamworks.NET and had a lot better time (If you plan on using Steam anyhow).