Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

SetRelayServerData error

Discussion in 'Unity Transport' started by JGRoos, Dec 24, 2023.

  1. JGRoos

    JGRoos

    Joined:
    Jul 17, 2018
    Posts:
    2
    Hey dudes
    I've run into this specific issue where Unity does not recognize the new RelayServerData(allocation, "dtls"), when placed inside the <UnityTransport>().SetRelayServerData().

    SetRelayServerData error.png
    If the image is not showing here is a link to it directly: https://ibb.co/vdbqgyp

    It's giving me the following error:
    "There is no argument given that corresponds to the required formal parameter 'port' of 'UnityTransport.SetRelayServerData(string, ushort, byte[], byte[], byte[], byte[], bool)'"

    Here is my code for Creating a lobby:
    Code (CSharp):
    1. public async void CreateLobby(string lobbyName, bool isPrivate)
    2.     {
    3.         try
    4.         {
    5.             joinedLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, 4, new CreateLobbyOptions { IsPrivate = isPrivate });
    6.             Allocation allocation = await AllocateRelay();
    7.             string relayJoinCode = await GetRelayJoinCode(allocation);
    8.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(allocation, "dtls"));
    9.             NetworkManager.Singleton.StartHost();
    10.             lobbyBackground.SetActive(false);
    11.             lobbyList.SetActive(false);
    12.         }
    13.         catch (LobbyServiceException e)
    14.         {
    15.             Debug.Log(e);
    16.         }
    17.     }
    Also here is the AllocateRelay() function that is referenced in the above code:
    Code (CSharp):
    1. private async Task<Allocation> AllocateRelay()
    2.     {
    3.         try
    4.         {
    5.             Allocation allocation = await RelayService.Instance.CreateAllocationAsync(3);
    6.             return allocation;
    7.         }
    8.         catch (RelayServiceException e)
    9.         {
    10.             Debug.LogException(e);
    11.             return default;
    12.         }
    13.     }
    What am I missing here?

    I get the same error even when I just copy the example from Unity here:
    https://docs.unity.com/ugs/en-us/manual/relay/manual/relay-and-ngo#Configur

    I believe I have all needed references, such as these:
    using Unity.Netcode.Transports.UTP;
    using Unity.Networking.Transport;
    using Unity.Networking.Transport.Relay;
    using Unity.Services.Relay;
    using Unity.Services.Relay.Models;

    I'm using Unity 2021.3.7f1, with Relay version 1.0.5 and Lobby version 1.0.3.
    Any help would be greatly appreciated!
    Sorry if this is unclear, I've never used the forum before.
     
  2. JGRoos

    JGRoos

    Joined:
    Jul 17, 2018
    Posts:
    2
    Ok nevermind, I decided to update to Unity 2022.3.16f1 (LTS), and now it's working.
    I assume the codebase changed quite a bit behind the scenes between 2021 and 2022, so if anyone comes across this issue, just try and update to a newer version.
    Sorry for wasting forum space on something so silly lol.