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 How do I change Unity Transport IP Address and Port during runtime?

Discussion in 'Netcode for GameObjects' started by yosimba2000, Jul 27, 2022.

  1. yosimba2000

    yosimba2000

    Joined:
    Jun 3, 2021
    Posts:
    25
  2. yosimba2000

    yosimba2000

    Joined:
    Jun 3, 2021
    Posts:
    25
    nvm got it, needed namespace "using Unity.Netcode.Transports.UTP" , then NetworkManager.GetComponent<UnityTransport>().ConnectionData.Address="someString";
     
  3. ALherbier

    ALherbier

    Joined:
    Sep 1, 2020
    Posts:
    8
    What about the port ?
    I am trying
    NetworkManager.GetComponent<UnityTransport>().ConnectionData.Port = ushort.Parse(PortNumberText.text)
    where PortNumberText.text is the string of a TextMeshPro UI element
    but Unity (more precisely C#) complains about the string format but I don't understand why.
    How did you do?
     
  4. ALherbier

    ALherbier

    Joined:
    Sep 1, 2020
    Posts:
    8
    OK for some reasons it seems that there is an extra character at the end of the string when I get it from the input field TMPro text. Removing this extra character removes the error.