Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Unity Mirror/ Playfab - OnServerReady not called after OnServerSceneChange

Discussion in 'Multiplayer' started by Volcaban, Mar 29, 2021.

  1. Volcaban

    Volcaban

    Joined:
    Nov 22, 2018
    Posts:
    1
    I'm trying to integrate a playfab multiplayer server into my Mirror multiplayer.
    The problem right now is that when I switch scenes from menu scene to the game scene it doesn't spawn any players.
    The OnServerSceneChanged method is called but the OnServerReady isn't called, this is where the player spawn is called.
    Also on the client part the method 'OnClientNotReadyMessageInternal' is called.

    Code (CSharp):
    1.         public override void OnServerSceneChanged(string sceneName)
    2.         {
    3.             if (sceneName.Contains("Scene_Map"))
    4.             {
    5.                 GameObject playerSpawnSystemInstance = Instantiate(playerSpawnSystem);
    6.                 NetworkServer.Spawn(playerSpawnSystemInstance);
    7.  
    8.                 GameObject roundSystemInstance = Instantiate(roundSystem);
    9.                 NetworkServer.Spawn(roundSystemInstance);
    10.             }
    11.         }
    12.  
    13.         public override void OnServerReady(NetworkConnection conn)
    14.         {
    15.             base.OnServerReady(conn);
    16.  
    17.             OnServerReadied?.Invoke(conn);
    18.         }
    Code (CSharp):
    1.         public override void OnStartServer()
    2.         {
    3.             Test_NetworkManagerLobby.OnServerReadied += SpawnPlayer;
    4.         }
    5.  
    6.         [Server]
    7.         public void SpawnPlayer(NetworkConnection conn)
    8.         {
    9.             Transform spawnPoint = spawnPoints.ElementAtOrDefault(nextIndex);
    10.  
    11.             if(spawnPoint == null)
    12.             {
    13.                 Debug.LogError($"Missing spawn point for player {nextIndex}");
    14.                 return;
    15.             }
    16.  
    17.             GameObject playerInstance = Instantiate(playerPrefab, spawnPoints[nextIndex].position, spawnPoints[nextIndex].rotation);
    18.             NetworkServer.AddPlayerForConnection(conn,playerInstance);
    19.  
    20.             nextIndex++;
    21.         }
     
  2. LeanneCreed21

    LeanneCreed21

    Joined:
    May 26, 2021
    Posts:
    7
    Hi there, I am having the same problem. I was wondering if you found a fix for this?
     
  3. koogelpotato

    koogelpotato

    Joined:
    Feb 20, 2020
    Posts:
    6
    Did you find an answer?