1
votes

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.

enter image description here

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.

enter image description here

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

enter image description here


Thanks for reminding, so I add "Awake()" into the test, then more weird things happened. A gameobject with "NetworkIdentity" will call its "Awake" before StartHost() to enable the gameobject in Editor Mode, but once you make a build, "Awake" will be call after StartHost(). This leads me more confused. :(

1
try awake instead of start - Bizhan

1 Answers

0
votes

Each network identity gameobject become disable as scene start and then Automatically active by the scene manager as unity docs stated:

All objects in the scene with a NetworkIdentity component will be disabled when the scene is loaded; on both the client and the server. Then, when the scene is fully loaded, NetworkServer.SpawnObjects() is called to activate these networked scene objects. This will be done automatically by the NetworkManager when the server scene finishes loading - or can be called directly by user code(more).

So according to my understanding, objects are enable one by one, so the order of log in your code is not weird(every object enable one by one and thier scripts start execute in the same order).