OnServerSceneChanged is not been called

OnServerSceneChanged is not being called and with this I can’t instantiate the GameOverHandler to manage the game over of the game. I don’t know why this is not working, please help me guys thanks a lot.

This is the code of my NetworkManager.

public class GameNetworkManager : NetworkManager
{
    [SerializeField] private GameObject unitSpawnerPrefab;
    [SerializeField] private GameOverHandler gameOverHandlerPrefab;

    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        base.OnServerAddPlayer(conn);

        var spawnerInstance = Instantiate(
            unitSpawnerPrefab,
            conn.identity.transform.position,
            conn.identity.transform.rotation
        );

        NetworkServer.Spawn(spawnerInstance, conn);
    }

    public override void ServerChangeScene(string newSceneName)
    {
        Debug.Log(SceneManager.GetActiveScene().name);
    }

    public override void OnServerSceneChanged(string sceneName)
    {
        Debug.Log(SceneManager.GetActiveScene().name);
        if(SceneManager.GetActiveScene().name.StartsWith("Demo"))
        {
            var gameOverHandlerInstance = Instantiate(gameOverHandlerPrefab);

            NetworkServer.Spawn(gameOverHandlerInstance.gameObject);
        }
    }
}

Hi there,
Is the scene changing correctly? It’s just OnServerSceneChanged that isn’t working?

Thanks a lot, the scenes weren’t changing at all because I was only working on the Demo scene. When I did the lobby area this problem was solved.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms