Changing scene using netcode for gameobjects

Hello,

I am using netcode for gameobjects to create a fps multiplayer game.

Game starts with a Lobby scene, when players are ready the host starts the game using relay.

I want to change the scene from lobby scene to the game scene. I am using
NetworkManager.SceneManager.LoadScene()
method to change the scene.
Then I subscribe the event
NetworkManager.SceneManager.OnLoadEventCompleted
to spawn players when game scene is loaded.

The problem is sometimes the player is not getting spawned. My understanding is it gets spawned in the previous scene (kind of). Sometimes it spawns correct but Unity throws error about the object (player) getting destroyed.

I read the documentations (and asked chat GPT, awful responses) still couldn’t figure it out.

Any help would be appreciated.

While I do not know any of your code, since you have not posted it here. Try making a hard check to see if you are in the correct scene when you want to spawn your objects. And make sure you call it at the correct spot.

Taking a build solved the problem. Don’t know why it occurs in editor mode. Guess I will take much more builds from now on.