"OnNetworkSpawn" is triggering before "Awake"!

I have a issue with scene synchronization.
Dynamic NetworkObjects behave differently in two different scenarios.

About project:
Unity : 2021.3.24f1
Netcode for GameObjects : 1.4.0
Scenes : Bootstrap, Main, Lobby, Game

Scenario 1 : This scenario is working well.

  • Host create Lobby and Create Relay than start the “StartHost()”
  • After these action Host join “Game” scene manually.
  • Client join same Lobby, Join same Relay than start “StartClient()”
  • After these action Client join “Game” scene automatically.
  • When client join the “Game” scene, “GameplayManager”'s Awake method trigger before the “Dynamic NetworkObject”'s “OnNetworkSpawn” method.

Scenario 2 : Broken scenario

  • Host create Lobby and Create Relay than start the “StartHost()”
  • Client join same Lobby, Join same Relay than start “StartClient()”
  • After these action Host join “Game” scene manually.
  • After these action Client join “Game” scene automatically.
  • Bug : When client join the “Game” scene “GameplayManager”'s Awake method trigger after “Dynamic NetworkObject”'s “OnNetworkSpawn” method.

GameplayManager is in the Game scene and “GameplayeManager-Init” log is in the its awake method!
This error occurs when “OnNetworkSpawn” tries to reach an object in GameplayManager.

Why is “OnNetworkSpawn” triggering at two different times in two different scenarios?
AND
How can I handle it this issue?

Edit:

  • In Scenario 2 => The Host awaits the Client on the Lobby scene and then joins the Game scene with the Client.
  • This error happens only Client, not Host player.

1 Like

I haven’t come accross this yet but the NVar docs say something that might be related.

Thanks for reply but, I have solved the issue.
The problem is about scene synchronization.
The host was creating the PlayerObject in theAwake method of GameplayManager.
I moved this action to “NetworkManager.Singleton.SceneManager.OnLoadComplete” method than the problem solved!

If you run into a problem like mine, I would recommend looking at the scene manager structure of the GalacticKittens

2 Likes