Search Unity

Question Received error message from Relay: self-connect not allowed. [ No information given ]

Discussion in 'Relay' started by a1creator, Feb 5, 2023.

  1. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    I'm currently trying to set up Relay for my project using lobby and netcode for gameobjects. Everything works as expected, but once I create the relay and start hosting on the Network Manager, I begin getting this one error message precisely every one second.

    The issue is that
    1 It doesn't provide me with any suggestion as to where the error might come from in the code
    and
    2 I know for a fact I don't have something that polls once a second. My lobby polls are very 3 seconds while I'm testing.

    I have tried everything that I thought might have an influence, to no luck. I know that I am not calling my JoinRelay function after creating the relay.

    This is my Relay code:
    Code (CSharp):
    1. private async Task RelayCreationSetup(int maxPlayers)
    2.     {
    3.         allocation = await RelayService.Instance.CreateAllocationAsync(maxPlayers);
    4.  
    5.         joinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
    6.  
    7.         relayServerData = new RelayServerData(allocation, "dtls");
    8.     }
    9.  
    10.     private async Task LoadGameSceneAndStartNetworking()
    11.     {
    12.         // don't mind how ugly this is, it works for testing purposes
    13.         this.TryGetComponent<UnityAsyncSceneLoading>(out UnityAsyncSceneLoading uasl);
    14.         if (uasl == null)
    15.             uasl = this.AddComponent<UnityAsyncSceneLoading>();
    16.  
    17.         // this just loads the game scene, waits until fully loaded, and then it starts the host (or joins if it is client)
    18.         await uasl.LoadSceneAndDo(gameSceneName, () => StartNetworking());
    19.     }
    20.  
    21.     public async Task<string> CreateRelay(int maxPlayers)
    22.     {
    23.         if (relayIsActive) return "";
    24.         try
    25.         {
    26.             relayIsActive = true;
    27.  
    28.             onBeginLoading.Invoke();
    29.  
    30.             await RelayCreationSetup(maxPlayers);
    31.  
    32.             // we need to go to game scene before using networkManager
    33.             // because it spawns the player object which has to be spawned in game scene
    34.             await LoadGameSceneAndStartNetworking();
    35.  
    36.             return joinCode;
    37.         }
    38.         catch (RelayServiceException e)
    39.         {
    40.             lobbyManager.DisplayError(e);
    41.         }
    42.  
    43.         return "";
    44.     }
    45.  
    46.     public async void JoinRelay(string joinCode)
    47.     {
    48.         if (relayIsActive) return;
    49.         try
    50.         {
    51.             relayIsActive = true;
    52.  
    53.             onBeginLoading.Invoke();
    54.  
    55.             var joinallocation = await RelayService.Instance.JoinAllocationAsync(joinCode);
    56.  
    57.             relayServerData = new RelayServerData(joinallocation, "dtls");
    58.  
    59.             // we need to go to game scene before using networkManager
    60.             // because it spawns the player object which has to be spawned in game scene
    61.             await LoadGameSceneAndStartNetworking();
    62.  
    63.         }
    64.         catch (RelayServiceException e)
    65.         {
    66.             lobbyManager.DisplayError(e);
    67.         }
    68.     }
    69.  
    70.     private void StartNetworking()
    71.     {
    72.         a1_Logs.Log("started networking");
    73.         NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
    74.  
    75.         NetworkManager.Singleton.StartClient();
    76.     }


    upload_2023-2-5_9-42-54.png
     
    NaTurek likes this.
  2. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    Hi a1-creator!
    Have you tried using
    Code (CSharp):
    1. NetworkManager.Singleton.StartHost();
    Instead of
    Code (CSharp):
    1. NetworkManager.Singleton.StartClient();
    Normally you should join the allocation you created as a host
    You can have a deeper look at this documentation: https://docs.unity.com/relay/en/manual/relay-and-ngo
    I hope this helps !
     
  3. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    I found this out a few hours after posting and forgot to remove it. It was a simple mistake caused by staring at the script so long I forgot what to look for..
    Thank you for your help, you are correct!