Search Unity

Question Cant redirect to another scene

Discussion in 'Netcode for GameObjects' started by TOminerTV, Aug 1, 2021.

  1. TOminerTV

    TOminerTV

    Joined:
    Jul 29, 2020
    Posts:
    2
    Hello Unity-Forum,

    i tried to redirect to another scene in my mlapi project.

    My clients call this ServerRPC:
    Code (CSharp):
    1.  
    2. [ServerRpc]
    3. private void SendUpdateUIServerRpc(LobbyPlayerState lobbyPlayerState)
    4. {
    5.     if(lobbyPlayerState.clientIsReady)
    6.         LocalPlayerDataHolder.AddReadyPlayer(lobbyPlayerState.clientID);
    7.     else
    8.         LocalPlayerDataHolder.RemoveReadyPlayer(lobbyPlayerState.clientID);
    9.  
    10.     UpdateUIClientRpc(lobbyPlayerState);
    11.  
    12.     Debug.Log("COUNT:::" + LocalPlayerDataHolder.GetReadyPlayers().Count);
    13.        
    14.     if(MultiplayerManager.AMOUNT_OF_MAX_PLAYERS == LocalPlayerDataHolder.GetReadyPlayersCount())
    15.         StartGame();
    16. }
    17.  
    18. .......
    19.  
    20.  
    21. public void StartGame()
    22. {
    23.     NetworkSceneManager.SwitchScene("TestScene");
    24. }
    25.  
    26.  
    Every time i get this error, i dont know why, the test-scene is a default empty scene. I had the same problem with my main game scene.

    The server error:
    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3.     at MLAPI.SceneManagement.NetworkSceneManager.OnSceneLoaded (System.Guid switchSceneGuid, System.IO.Stream objectStream) [0x0003f] in <9bdc63d7f06c4ec696592b17b3c19305>:0
    4.    at MLAPI.SceneManagement.NetworkSceneManager+<>c__DisplayClass24_0.<SwitchScene>b__0 (UnityEngine.AsyncOperation asyncOp2) [0x0000b] in <9bdc63d7f06c4ec696592b17b3c19305>:0
    5.    at (wrapper delegate-invoke) System.Action`1[UnityEngine.AsyncOperation].invoke_void_T(UnityEngine.AsyncOperation)
    6.    at UnityEngine.AsyncOperation.InvokeCompletionEvent () [0x0000f] in <5280c7b5cfc04797bf38af3009a83143>:0
    7.  
     
  2. TOminerTV

    TOminerTV

    Joined:
    Jul 29, 2020
    Posts:
    2
    I have solved the problem. On the one hand, it may be that scene changing is deactivated in the NetworkManager component.

    On the other hand, it is possible that the NetworkManager is destroyed, as DontDestroy only works if the component is on a root element.

    -----------------------------------------------------------------------------------------------------------------

    Habe das Problem gelöst, zum einen kann es sein das in der NetworkManager Komponente das Szenen-Wechseln deaktiviert ist.

    Zum anderen ist es möglich das der NetworkManager zerstört wird, da DontDestroy nur wirkt wenn die Komponente auf einem Root-Element liegt.