I added a new test NetworkObject (with default NetworkObject settings) in the hierarchy to be sure it’s not disabled then I tested the behavior on server and client side and I got same result.
The test objects’s order of methods like this:
Awake => OnEnable => OnNetworkSpawn => Start.
The test object isn’t child object, it is placed on the root of hierarchy. Also the object isn’t in the same scene as NetworkManager. The scene containing the test NetworkObject is loaded with networkManager.SceneManager.LoadScene(“Gameplay”, UnityEngine.SceneManagement.LoadSceneMode.Single);
Did you load this scene with NetworkManager.Singleton.SceneManager ? If it’s the first scene in the build it may behave differently.
Regardless of the execution order, it is best practice to ignore the execution order of Start and OnNetworkSpawn and treat it as undefined. Because at some point you may want to make an in-scene placed network object a prefab or vice versa and just like that, your scripts might break.
Thus perform anything in Start either in Awake (if it can be done this early) or use OnNetworkSpawn. This puts your mind at ease too.
Yes as I mentioned above, This isn’t the first sene and it is loaded by “NetworkManager.Singleton.SceneManager”
I’ll keep that suggestion in mind.
Actually, it’s not really a big issue for me, but I wanted to make sure whether I did wrong or right. Because this behavior doesn’t match on documentation.
I’ve come across the same thing and I did mention it here. I’ve not looked into it but just noticed in passing that in some test projects the order is correct and sometimes not. I’ll see about raising an issue for it to see if we can get some clarification.
Thank you for pointing this out.
It would appear Unity 6’s SceneManager handles the instantiation process more like it would if you were to dynamically create a network prefab instance and spawn it.
We will start tracking this and update the NGO v2 documentation to reflect this change. I replicated what you are seeing and indeed it does appear that both dynamically an in-scene placed NetworkObjects will be following the same order of operations:
Awake
OnNetworkPreSpawn
OnNetworkSpawn
OnNetworkPostSpawn
Start
However, for a scene that is already preloaded with in-scene placed NetworkObjects prior to starting the NetworkManager it will still follow the same pattern:
I’m seeing this happen in Unity 6 but not consistently. In a project I have a single scene where the order is incorrect, if I reproduce it identically in a new scene the order is correct. If I make a file system duplicate of the first files the order remains incorrect. If I copy/paste the game objects into a new scene the order is correct but is incorrect after a re-import.
I hope you can make more sense out of this than I can.