Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Teleportation in VR does not work for the clients + how to retain lobby for clients after host quits

Discussion in 'Lobby' started by marzdh, Aug 14, 2023.

  1. marzdh

    marzdh

    Joined:
    Jun 3, 2013
    Posts:
    31
    Hello all,

    I have 2 questions relating to the use of Lobby with Relay using Netcode for the VR platform -

    1. Teleportation does not work for the client who joins in after the host. The code below illustrates how the host and client join a lobby. Is there some communication required from the client to be sent for teleportation?
    Teleportation works fine for the host.

    Code (CSharp):
    1. public async void CreateLobby() {
    2.             try
    3.             {
    4.             CreateLobbyOptions createLobbyOptions = new CreateLobbyOptions
    5.                 {
    6.                     IsPrivate = false
    7.                 };
    8.  
    9.                 joinedLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, createLobbyOptions);
    10.  
    11.                 Allocation allocation = await AllocateRelay();
    12.                 string relayJoinCode = await GetRelayJoinCode(allocation);
    13.  
    14.                 await LobbyService.Instance.UpdateLobbyAsync(joinedLobby.Id, new UpdateLobbyOptions
    15.                 {
    16.                     Data = new Dictionary<string, DataObject>
    17.                     {
    18.                         {KEY_RELAY_JOIN_CODE,  new DataObject(DataObject.VisibilityOptions.Member,relayJoinCode)}
    19.                     }
    20.                 });
    21.                 RelayServerData relayServerData = new RelayServerData(allocation, "dtls");
    22.                 NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
    23.  
    24.                 NetworkManager.Singleton.StartHost();
    25.         }
    26.         catch(LobbyServiceException e)
    27.             {
    28.                 Debug.Log(e);
    29.             }
    30.     }
    31.  
    32.  
    33. public async void JoinLobbyWithID(string lobbyID) {
    34.         try {
    35.             Lobby joinedLobby = await Lobbies.Instance.JoinLobbyByIdAsync(lobbyID); //joinLobbyByIdOptions);
    36.             string relayJoinCode = joinedLobby.Data[KEY_RELAY_JOIN_CODE].Value;
    37.  
    38.             JoinAllocation joinAllocation = await JoinRelay(relayJoinCode);
    39.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(joinAllocation, "dtls"));
    40.          
    41.             NetworkManager.Singleton.StartClient();
    42.            
    43.         }
    44.         catch (LobbyServiceException e) {
    45.             Debug.Log(e);
    46.         }

    2. I remember reading in the documentation that if a host leaves the lobby, the next player joined as a client becomes the host. However, in my code, when the host leaves, all the clients also disconnect. How can I prevent this from happening? I want the lobby to disconnect only after the last player leaves.
     
  2. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    156
    I'm not familiar with VR but, I can answer you second question.
    There isn't Host migration on Relay but there is in Lobby.
    As I see, you are using NGO and Relay to connect players together. This means that all other clients will be disconnected when the Host player leaves the Relay.
    So you have to create your own host-migration system for Relay and NGO.
    I can suggest you two page for host migration.
    Page1 Page2
     
  3. marzdh

    marzdh

    Joined:
    Jun 3, 2013
    Posts:
    31
    @Mj-Kkaya
    I'm new to NGO so my questions may seem a little raw and not detailed.

    I tried using only Lobby, but all players still disconnected after host left. Is there a way to handle this?
    Also another observation is, when using only Lobby, the game does not play on different IPs. Am I missing something here?
     
  4. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    156
    It should'n be. If you use only Lobby without using Relay and NGO, other players won't disconnect.
    Lobby Host migration document page.

    I guess, your VR game needs to NGO and NGO needs to Relay connection.
    So how do you initialize "Players" objects without using Relay and NGO?
     
  5. marzdh

    marzdh

    Joined:
    Jun 3, 2013
    Posts:
    31
    To elaborate the issue 1 further, it seems like the Teleportation Area component requires a teleportation provider. The problem is, when multiple people join, the teleportation area takes the Host XR Rig's teleportation provider by default. So even if I write a code to override that and set it to the Client, it doesn't accept it.

    Any thoughts?