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?