docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class UnityTransport

    The Netcode for GameObjects NetworkTransport for UnityTransport. Note: This is highly recommended to use over UNet.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    NetworkTransport
    UnityTransport
    Implements
    INetworkStreamDriverConstructor
    Inherited Members
    NetworkTransport.IsSupported
    NetworkTransport.OnTransportEvent
    NetworkTransport.InvokeOnTransportEvent(NetworkEvent, ulong, ArraySegment<byte>, float)
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.didStart
    MonoBehaviour.didAwake
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.GetComponentIndex()
    Component.CompareTag(string)
    Component.CompareTag(TagHandle)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Netcode.Transports.UTP
    Assembly: Unity.Netcode.Runtime.dll
    Syntax
    [AddComponentMenu("Netcode/Unity Transport")]
    public class UnityTransport : NetworkTransport, INetworkStreamDriverConstructor

    Fields

    ConnectionData

    The connection (address) data for this UnityTransport instance. This is where you can change IP Address, Port, or server's listen address. UnityTransport.ConnectionAddressData

    Declaration
    public UnityTransport.ConnectionAddressData ConnectionData
    Field Value
    Type Description
    UnityTransport.ConnectionAddressData

    DebugSimulator

    Can be used to simulate poor network conditions such as:

    • packet delay/latency
    • packet jitter (variances in latency, see: https://en.wikipedia.org/wiki/Jitter)
    • packet drop rate (packet loss)
    Declaration
    [Obsolete("DebugSimulator is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)]
    public UnityTransport.SimulatorParameters DebugSimulator
    Field Value
    Type Description
    UnityTransport.SimulatorParameters

    InitialMaxPacketQueueSize

    The default maximum (receive) packet queue size

    Declaration
    public const int InitialMaxPacketQueueSize = 128
    Field Value
    Type Description
    int

    InitialMaxPayloadSize

    The default maximum payload size

    Declaration
    public const int InitialMaxPayloadSize = 6144
    Field Value
    Type Description
    int

    InitialMaxSendQueueSize

    The default maximum send queue size

    Declaration
    [Obsolete("MaxSendQueueSize is now determined dynamically (can still be set programmatically using the MaxSendQueueSize property). This initial value is not used anymore.", false)]
    public const int InitialMaxSendQueueSize = 98304
    Field Value
    Type Description
    int

    m_Driver

    Declaration
    protected NetworkDriver m_Driver
    Field Value
    Type Description
    NetworkDriver

    m_NetworkManager

    NetworkManager associated to this transport instance

    Declaration
    protected NetworkManager m_NetworkManager
    Field Value
    Type Description
    NetworkManager

    s_DriverConstructor

    The global INetworkStreamDriverConstructor implementation

    Declaration
    public static INetworkStreamDriverConstructor s_DriverConstructor
    Field Value
    Type Description
    INetworkStreamDriverConstructor

    Properties

    ConnectTimeoutMS

    Timeout in milliseconds indicating how long we will wait until we send a new connection attempt.

    Declaration
    public int ConnectTimeoutMS { get; set; }
    Property Value
    Type Description
    int

    DisconnectTimeoutMS

    Inactivity timeout after which a connection will be disconnected.

    Declaration
    public int DisconnectTimeoutMS { get; set; }
    Property Value
    Type Description
    int
    Remarks

    The connection needs to receive data from the connected endpoint within this timeout. Note that with heartbeats enabled, simply not sending any data will not be enough to trigger this timeout (since heartbeats count as connection events).

    DriverConstructor

    Returns either the global INetworkStreamDriverConstructor implementation or the current UnityTransport instance

    Declaration
    public INetworkStreamDriverConstructor DriverConstructor { get; }
    Property Value
    Type Description
    INetworkStreamDriverConstructor

    HeartbeatTimeoutMS

    Timeout in milliseconds after which a heartbeat is sent if there is no activity.

    Declaration
    public int HeartbeatTimeoutMS { get; set; }
    Property Value
    Type Description
    int

    MaxConnectAttempts

    The maximum amount of connection attempts we will try before disconnecting.

    Declaration
    public int MaxConnectAttempts { get; set; }
    Property Value
    Type Description
    int

    MaxPacketQueueSize

    The maximum amount of packets that can be in the internal send/receive queues.

    Declaration
    public int MaxPacketQueueSize { get; set; }
    Property Value
    Type Description
    int
    Remarks

    Basically this is how many packets can be sent/received in a single update/frame.

    MaxPayloadSize

    The maximum size of an unreliable payload that can be handled by the transport.

    Declaration
    public int MaxPayloadSize { get; set; }
    Property Value
    Type Description
    int

    MaxSendQueueSize

    The maximum size in bytes of the transport send queue.

    Declaration
    public int MaxSendQueueSize { get; set; }
    Property Value
    Type Description
    int
    Remarks

    The send queue accumulates messages for batching and stores messages when other internal send queues are full. Note that there should not be any need to set this value manually since the send queue size is dynamically sized based on need.

    This value should only be set if you have particular requirements (e.g. if you want to limit the memory usage of the send queues). Note however that setting this value too low can easily lead to disconnections under heavy traffic.

    Protocol

    The current ProtocolType used by the transport

    Declaration
    public UnityTransport.ProtocolType Protocol { get; }
    Property Value
    Type Description
    UnityTransport.ProtocolType

    ServerClientId

    The client id used to represent the server.

    Declaration
    public override ulong ServerClientId { get; }
    Property Value
    Type Description
    ulong
    Overrides
    NetworkTransport.ServerClientId

    UseEncryption

    Declaration
    public bool UseEncryption { get; set; }
    Property Value
    Type Description
    bool

    UseWebSockets

    Declaration
    public bool UseWebSockets { get; set; }
    Property Value
    Type Description
    bool

    Methods

    Connect(NetworkEndpoint)

    Declaration
    protected virtual NetworkConnection Connect(NetworkEndpoint serverEndpoint)
    Parameters
    Type Name Description
    NetworkEndpoint serverEndpoint
    Returns
    Type Description
    NetworkConnection

    CreateDriver(UnityTransport, out NetworkDriver, out NetworkPipeline, out NetworkPipeline, out NetworkPipeline)

    Creates the internal NetworkDriver

    Declaration
    public void CreateDriver(UnityTransport transport, out NetworkDriver driver, out NetworkPipeline unreliableFragmentedPipeline, out NetworkPipeline unreliableSequencedFragmentedPipeline, out NetworkPipeline reliableSequencedPipeline)
    Parameters
    Type Name Description
    UnityTransport transport

    The owner transport

    NetworkDriver driver

    The driver

    NetworkPipeline unreliableFragmentedPipeline

    The UnreliableFragmented NetworkPipeline

    NetworkPipeline unreliableSequencedFragmentedPipeline

    The UnreliableSequencedFragmented NetworkPipeline

    NetworkPipeline reliableSequencedPipeline

    The ReliableSequenced NetworkPipeline

    DisconnectLocalClient()

    Disconnects the local client from the remote

    Declaration
    public override void DisconnectLocalClient()
    Overrides
    NetworkTransport.DisconnectLocalClient()

    DisconnectRemoteClient(ulong)

    Disconnects a remote client from the server

    Declaration
    public override void DisconnectRemoteClient(ulong clientId)
    Parameters
    Type Name Description
    ulong clientId

    The client to disconnect

    Overrides
    NetworkTransport.DisconnectRemoteClient(ulong)

    GetCurrentRtt(ulong)

    Gets the current RTT for a specific client

    Declaration
    public override ulong GetCurrentRtt(ulong clientId)
    Parameters
    Type Name Description
    ulong clientId

    The client RTT to get

    Returns
    Type Description
    ulong

    The RTT

    Overrides
    NetworkTransport.GetCurrentRtt(ulong)

    GetLocalEndpoint()

    Gets the local sytem's Unity.Networking.Transport.NetworkEndpoint that is assigned for the current network session.

    Declaration
    public NetworkEndpoint GetLocalEndpoint()
    Returns
    Type Description
    NetworkEndpoint

    Unity.Networking.Transport.NetworkEndpoint

    Remarks

    If the driver is not created it will return an invalid Unity.Networking.Transport.NetworkEndpoint.

    GetNetworkDriver()

    Gets a reference to the Unity.Networking.Transport.NetworkDriver.

    Declaration
    public ref NetworkDriver GetNetworkDriver()
    Returns
    Type Description
    NetworkDriver

    ref Unity.Networking.Transport.NetworkDriver

    Initialize(NetworkManager)

    Initializes the transport

    Declaration
    public override void Initialize(NetworkManager networkManager = null)
    Parameters
    Type Name Description
    NetworkManager networkManager

    The NetworkManager that initialized and owns the transport

    Overrides
    NetworkTransport.Initialize(NetworkManager)

    OnCurrentTopology()

    Declaration
    protected override NetworkTopologyTypes OnCurrentTopology()
    Returns
    Type Description
    NetworkTopologyTypes
    Overrides
    NetworkTransport.OnCurrentTopology()

    PollEvent(out ulong, out ArraySegment<byte>, out float)

    Polls for incoming events, with an extra output parameter to report the precise time the event was received.

    Declaration
    public override NetworkEvent PollEvent(out ulong clientId, out ArraySegment<byte> payload, out float receiveTime)
    Parameters
    Type Name Description
    ulong clientId

    The clientId this event is for

    ArraySegment<byte> payload

    The incoming data payload

    float receiveTime

    The time the event was received, as reported by m_RealTimeProvider.RealTimeSinceStartup.

    Returns
    Type Description
    NetworkEvent

    Returns the event type

    Overrides
    NetworkTransport.PollEvent(out ulong, out ArraySegment<byte>, out float)

    Send(ulong, ArraySegment<byte>, NetworkDelivery)

    Send a payload to the specified clientId, data and networkDelivery.

    Declaration
    public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDelivery networkDelivery)
    Parameters
    Type Name Description
    ulong clientId

    The clientId to send to

    ArraySegment<byte> payload

    The data to send

    NetworkDelivery networkDelivery

    The delivery type (QoS) to send data with

    Overrides
    NetworkTransport.Send(ulong, ArraySegment<byte>, NetworkDelivery)

    SetClientRelayData(string, ushort, byte[], byte[], byte[], byte[], bool)

    Set the relay server data for the host.

    Declaration
    public void SetClientRelayData(string ipAddress, ushort port, byte[] allocationId, byte[] key, byte[] connectionData, byte[] hostConnectionData, bool isSecure = false)
    Parameters
    Type Name Description
    string ipAddress

    IP address or hostname of the relay server.

    ushort port

    UDP port of the relay server.

    byte[] allocationId

    Allocation ID as a byte array.

    byte[] key

    Allocation key as a byte array.

    byte[] connectionData

    Connection data as a byte array.

    byte[] hostConnectionData

    Host's connection data as a byte array.

    bool isSecure

    Whether the connection is secure (uses DTLS).

    SetClientSecrets(string, string)

    Set the client parameters for encryption.

    Declaration
    public void SetClientSecrets(string serverCommonName, string caCertificate = null)
    Parameters
    Type Name Description
    string serverCommonName

    Common name of the server (typically hostname).

    string caCertificate

    CA certificate used to validate the server's authenticity.

    Remarks

    If the CA certificate is not provided, validation will be done against the OS/browser certificate store. This is what you'd want if using certificates from a known provider. For self-signed certificates, the CA certificate needs to be provided.

    The CA certificate (if provided) is expected to be in the PEM format, including the begin/end markers like -----BEGIN CERTIFICATE-----.

    SetConnectionData(string, ushort, string)

    Sets IP and Port information. This will be ignored if using the Unity Relay and you should call SetRelayServerData(string, ushort, byte[], byte[], byte[], byte[], bool)

    Declaration
    public void SetConnectionData(string ipv4Address, ushort port, string listenAddress = null)
    Parameters
    Type Name Description
    string ipv4Address

    The remote IP address (despite the name, can be an IPv6 address)

    ushort port

    The remote port

    string listenAddress

    The local listen address

    SetConnectionData(NetworkEndpoint, NetworkEndpoint)

    Sets IP and Port information. This will be ignored if using the Unity Relay and you should call SetRelayServerData(string, ushort, byte[], byte[], byte[], byte[], bool)

    Declaration
    public void SetConnectionData(NetworkEndpoint endPoint, NetworkEndpoint listenEndPoint = default)
    Parameters
    Type Name Description
    NetworkEndpoint endPoint

    The remote end point

    NetworkEndpoint listenEndPoint

    The local listen endpoint

    SetDebugSimulatorParameters(int, int, int)

    Set the parameters for the debug simulator.

    Declaration
    [Obsolete("SetDebugSimulatorParameters is no longer supported and has no effect. Use Network Simulator from the Multiplayer Tools package.", false)]
    public void SetDebugSimulatorParameters(int packetDelay, int packetJitter, int dropRate)
    Parameters
    Type Name Description
    int packetDelay

    Packet delay in milliseconds.

    int packetJitter

    Packet jitter in milliseconds.

    int dropRate

    Packet drop percentage.

    SetHostRelayData(string, ushort, byte[], byte[], byte[], bool)

    Set the relay server data for the host.

    Declaration
    public void SetHostRelayData(string ipAddress, ushort port, byte[] allocationId, byte[] key, byte[] connectionData, bool isSecure = false)
    Parameters
    Type Name Description
    string ipAddress

    IP address or hostname of the relay server.

    ushort port

    UDP port of the relay server.

    byte[] allocationId

    Allocation ID as a byte array.

    byte[] key

    Allocation key as a byte array.

    byte[] connectionData

    Connection data as a byte array.

    bool isSecure

    Whether the connection is secure (uses DTLS).

    SetRelayServerData(string, ushort, byte[], byte[], byte[], byte[], bool)

    Set the relay server data for the server.

    Declaration
    public void SetRelayServerData(string ipv4Address, ushort port, byte[] allocationIdBytes, byte[] keyBytes, byte[] connectionDataBytes, byte[] hostConnectionDataBytes = null, bool isSecure = false)
    Parameters
    Type Name Description
    string ipv4Address

    IP address or hostname of the relay server.

    ushort port

    UDP port of the relay server.

    byte[] allocationIdBytes

    Allocation ID as a byte array.

    byte[] keyBytes

    Allocation key as a byte array.

    byte[] connectionDataBytes

    Connection data as a byte array.

    byte[] hostConnectionDataBytes

    The HostConnectionData as a byte array.

    bool isSecure

    Whether the connection is secure (uses DTLS).

    SetRelayServerData(RelayServerData)

    Set the relay server data (using the lower-level Unity Transport data structure).

    Declaration
    public void SetRelayServerData(RelayServerData serverData)
    Parameters
    Type Name Description
    RelayServerData serverData

    Data for the Relay server to use.

    SetServerSecrets(string, string)

    Set the server parameters for encryption.

    Declaration
    public void SetServerSecrets(string serverCertificate, string serverPrivateKey)
    Parameters
    Type Name Description
    string serverCertificate

    Public certificate for the server (PEM format).

    string serverPrivateKey

    Private key for the server (PEM format).

    Remarks

    The public certificate and private key are expected to be in the PEM format, including the begin/end markers like -----BEGIN CERTIFICATE-----.

    Shutdown()

    Shuts down the transport

    Declaration
    public override void Shutdown()
    Overrides
    NetworkTransport.Shutdown()

    StartClient()

    Connects client to the server Note: When this method returns false it could mean:

    • You are trying to start a client that is already started
    • It failed during the initial port binding when attempting to begin to connect
    Declaration
    public override bool StartClient()
    Returns
    Type Description
    bool

    true if the client was started and false if it failed to start the client

    Overrides
    NetworkTransport.StartClient()

    StartServer()

    Starts to listening for incoming clients Note: When this method returns false it could mean:

    • You are trying to start a client that is already started
    • It failed during the initial port binding when attempting to begin to connect
    Declaration
    public override bool StartServer()
    Returns
    Type Description
    bool

    true if the server was started and false if it failed to start the server

    Overrides
    NetworkTransport.StartServer()

    Implements

    INetworkStreamDriverConstructor
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)