Search Unity

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

Question An extra Scene gets loaded on client side while joining a lobby.

Discussion in 'Multiplayer' started by rayanghosh99, Feb 6, 2024.

  1. rayanghosh99

    rayanghosh99

    Joined:
    Sep 4, 2020
    Posts:
    18
    Somehow a scene gets loaded (additive) on the client side when joining a lobby,
    I debugged every script but dint find the Scene-Manager load scene or load scene async
    any where... I need help.

    here is code on Create or Join lobby
    Code (CSharp):
    1.   public async void CreateOrJoinLobby()
    2.   {
    3.       MP_pannel.SetActive(true);
    4.       _connectedLobby = await QuickJoinLobby() ?? await CreateLobby();
    5.   }
    6.  
    7.   private async Task<Lobby> QuickJoinLobby()
    8.   {
    9.       try
    10.       {
    11.           // Attempt to join a lobby in progress
    12.           var lobby = await Lobbies.Instance.QuickJoinLobbyAsync();
    13.  
    14.           // If we found one, grab the relay allocation details
    15.           var a = await RelayService.Instance.JoinAllocationAsync(lobby.Data[JoinCodeKey].Value);
    16.  
    17.           // Set the details to the transform
    18.           SetTransformAsClient(a);
    19.  
    20.           // Join the game room as a client
    21.           NetworkManager.Singleton.StartClient();
    22.           return lobby;
    23.       }
    24.       catch (Exception e)
    25.       {
    26.           Debug.Log($"No lobbies available via quick join, " + e);
    27.           return null;
    28.       }
    29.   }
    30.  
    31.   private async Task<Lobby> CreateLobby()
    32.   {
    33.  
    34.       try
    35.       {
    36.           const int maxPlayers = 2;
    37.  
    38.           // Create a relay allocation and generate a join code to share with the lobby
    39.           var a = await RelayService.Instance.CreateAllocationAsync(maxPlayers);
    40.           var joinCode = await RelayService.Instance.GetJoinCodeAsync(a.AllocationId);
    41.  
    42.           // Create a lobby, adding the relay join code to the lobby data
    43.           var options = new CreateLobbyOptions
    44.           {
    45.               Data = new Dictionary<string, DataObject> { { JoinCodeKey, new DataObject(DataObject.VisibilityOptions.Public, joinCode) } }
    46.           };
    47.           var lobby = await Lobbies.Instance.CreateLobbyAsync("Useless Lobby Name", maxPlayers, options);
    48.  
    49.           // Send a heartbeat every 15 seconds to keep the room alive
    50.           StartCoroutine(HeartbeatLobbyCoroutine(lobby.Id, 15));
    51.  
    52.           // Set the game room to use the relay allocation
    53.           _transport.SetHostRelayData(a.RelayServer.IpV4, (ushort)a.RelayServer.Port, a.AllocationIdBytes, a.Key, a.ConnectionData);
    54.  
    55.           // Start the room. I'm doing this immediately, but maybe you want to wait for the lobby to fill up
    56.           NetworkManager.Singleton.StartHost();
    57.           return lobby;
    58.       }
    59.       catch (Exception e)
    60.       {
    61.           Debug.LogFormat("Failed creating a lobby, " + e);
    62.           return null;
    63.       }
    64.   }

    I tried debugging this around a lot,
    checked all events, actions none triggers this extra scene load; Neither am I using any RPCs that will let something like this occur.

    Only thing I understand right now is, it is only happening on client side. (I am sure about this.)
    Host does not loads an extra level.

    how do I figure this...:cool: I have wasted too many hours on this. need help.
     
    Last edited: Feb 6, 2024