#Player objects despawn in new scene

4 messages · Page 1 of 1 (latest)

broken palm
#

I have a Lobby and Game Scene setup. For swapping the lobby player objects with the new ingame player objects, I use the following code:

public override void ServerChangeScene(string newSceneName)
{
    // From menu to game
    if (SceneManager.GetActiveScene().name == menuScene && newSceneName == gameScene)
    {
        for (int i = RoomPlayers.Count - 1; i >= 0; i--)
        {
            var conn = RoomPlayers[i].connectionToClient;
            var gameplayerInstance = Instantiate(gamePlayerPrefab);

            NetworkServer.ReplacePlayerForConnection(conn, gameplayerInstance.gameObject, ReplacePlayerOptions.Destroy);
        }
    }

    base.ServerChangeScene(newSceneName);
}

However, when the scene gets loaded, for a short period of time (0.5 s) both players (I test with two instances of the game for testing multiplayer) both playerobjects get spawned, but then right after that they get deleted again. I already registered the player object in the NetworkManager as Spawnable Prefabs (see image).
Does anybody know why this happens?

viral fiber
broken palm
#

I am currently not using the built in NetworkRoomManager and NetworkRoomPlayer, what I am using is the custom one by the Dapper DIno Mirror Tutorial series. Is there anything I could have messed up causing the despawn issue? Because everything already works fine but this small step just won't work. Had I known that a built in solution exists I would've used that, but I think I'm too far in the implementation for swapping the system.

broken palm
#

I found the issue.
In the NetworkGamePlayer.cs script, in the OnStartClient() override
DontDestroyOnLoad(gameObject); was not set.