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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved access unity transport via code

Discussion in 'Unity Transport' started by miccalisto, Apr 21, 2023.

  1. miccalisto

    miccalisto

    Joined:
    Feb 20, 2018
    Posts:
    40
    How do I access unity transport with code? I want to change the protocol from relay unity transport to unity transport depending on whether it's a singleplayer or multiplayer mode.
    How do I do that?
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    381
    Just access the
    UnityTransport
    component on the game object where your
    NetworkManager
    is. Here's an example where this is done to configure the Relay parameters. To change the transport between using Relay and direct connections, simply configure it with the appropriate parameters. Calling
    SetRelayServerData
    will automatically change the protocol type to Relay, and calling
    SetConnectionData
    will automatically set it to use direct connections.