docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NetworkDriverStore

    Store and manage an array of NetworkDriver. The capacity is fixed to Capacity. The driver registration should start by calling BeginDriverRegistration() and terminate with EndDriverRegistration(). The store also provide some accessor and utlilty methods.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.NetCode
    Assembly: Unity.NetCode.dll
    Syntax
    public struct NetworkDriverStore

    Fields

    Capacity

    The fixed capacity of the driver container.

    Declaration
    public const int Capacity = 3
    Field Value
    Type Description
    int

    FirstDriverId

    The first assigned uniqued identifier to each driver.

    Declaration
    public const int FirstDriverId = 1
    Field Value
    Type Description
    int

    Properties

    DriversCount

    The number of registered drivers. Must be always less then the total driver Capacity.

    Declaration
    public int DriversCount { get; }
    Property Value
    Type Description
    int

    FirstDriver

    The first driver id present in the store. Can be used to iterate over all registered drivers in a for loop.

    Declaration
    public int FirstDriver { get; }
    Property Value
    Type Description
    int
    Examples
      for(int i= driverStore.FirstDriver; i < driverStore.LastDriver; ++i)
                 {
                      ref var instance = ref driverStore.GetDriverInstance(i);
                      ....
                 }
    

    HasListeningInterfaces

    Return true if there is at least one driver listening for incoming connections.

    Declaration
    public bool HasListeningInterfaces { get; }
    Property Value
    Type Description
    bool

    IsAnyUsingSimulator

    Return true if the driver store contains a driver that has a simulator pipeline.

    Declaration
    public bool IsAnyUsingSimulator { get; }
    Property Value
    Type Description
    bool

    IsCreated

    Denote if the store has at least one driver registered

    Declaration
    public bool IsCreated { get; }
    Property Value
    Type Description
    bool

    LastDriver

    The last driver id present in the store. Can be used to iterate over all registered drivers in a for loop.

    Declaration
    public int LastDriver { get; }
    Property Value
    Type Description
    int
    Examples
      for(int i= driverStore.FirstDriver; i < driverStore.LastDriver; ++i)
                 {
                      ref var instance = ref driverStore.GetDriverInstance(i).
                      ....
                 }
    

    Methods

    Disconnect(NetworkStreamConnection)

    Utility method to disconnect the NetworkStreamConnection connection.

    Declaration
    public void Disconnect(NetworkStreamConnection connection)
    Parameters
    Type Name Description
    NetworkStreamConnection connection
    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    Dispose()

    Dispose all the registered drivers instances and their allocated resources.

    Declaration
    public void Dispose()

    ForEachDriver(DriverVisitor)

    Invoke the delegate on all registered drivers.

    Declaration
    [Obsolete("The ForEachDriver has been deprecated. Please always iterate over the driver using a for loop, using the FirstDriver and LastDriver ids instead.")]
    public void ForEachDriver(NetworkDriverStore.DriverVisitor visitor)
    Parameters
    Type Name Description
    NetworkDriverStore.DriverVisitor visitor

    Visitor to invoke with the driver instance and ID

    GetConnectionState(NetworkStreamConnection)

    Return the state of the NetworkStreamConnection connection.

    Declaration
    public NetworkConnection.State GetConnectionState(NetworkStreamConnection connection)
    Parameters
    Type Name Description
    NetworkStreamConnection connection

    A client or server connection

    Returns
    Type Description
    NetworkConnection.State

    The state of the NetworkStreamConnection connection

    Exceptions
    Type Condition
    InvalidOperationException

    Throw an exception if the driver associated to the connection is not found

    GetDriverInstance(int)

    Return the NetworkDriverStore.NetworkDriverInstance instance with the given driverId.

    Declaration
    [Obsolete("Prefer GetDriverInstanceRW or GetDriverInstanceRO to avoid copying.", false)]
    public readonly ref NetworkDriverStore.NetworkDriverInstance GetDriverInstance(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    NetworkDriverStore.NetworkDriverInstance

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Remarks

    The method return a copy of the driver instance not a reference. While this is suitable for almost all the use cases, since the driver is trivially copyable, be aware that calling some of the Driver class methods, like ScheduleUpdate, that update internal driver data (that aren't suited to be copied around) may not work as expected.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    GetDriverInstanceRO(int)

    Return a reference to the NetworkDriverStore.NetworkDriverInstance instance with the given driverId.

    Declaration
    public ref readonly NetworkDriverStore.NetworkDriverInstance GetDriverInstanceRO(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    NetworkDriverStore.NetworkDriverInstance

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    GetDriverInstanceRW(int)

    Return a reference to the NetworkDriverStore.NetworkDriverInstance instance with the given driverId.

    Declaration
    public ref NetworkDriverStore.NetworkDriverInstance GetDriverInstanceRW(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    NetworkDriverStore.NetworkDriverInstance

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    GetDriverRO(int)

    Retrieve a Read-Only reference to the Unity.Networking.Transport.NetworkDriver for the given driverId.

    Declaration
    public ref readonly NetworkDriver GetDriverRO(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    NetworkDriver

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    GetDriverRW(int)

    Retrieve a ReadWrite reference to the Unity.Networking.Transport.NetworkDriver for the given driverId.

    Declaration
    public ref NetworkDriver GetDriverRW(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    NetworkDriver

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    GetDriverType(int)

    Return the transport type used by the registered driver.

    Declaration
    public TransportType GetDriverType(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    TransportType

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    GetNetworkDriver(int)

    Return the Unity.Networking.Transport.NetworkDriver with the given driverId.

    Declaration
    [Obsolete("Prefer GetDriverRW or GetDriverRO to avoid copying.", false)]
    public readonly NetworkDriver GetNetworkDriver(int driverId)
    Parameters
    Type Name Description
    int driverId

    The index of the target driver. See FirstDriver and LastDriver.

    Returns
    Type Description
    NetworkDriver

    The NetworkDriverStore.NetworkDriverData instance, by readonly ref.

    Exceptions
    Type Condition
    InvalidOperationException

    Throws if driverId is out of range.

    RegisterDriver(TransportType, in NetworkDriverInstance)

    Add a new driver to the store. Throw exception if all drivers slot are already occupied or the driver is not created/valid

    Declaration
    public int RegisterDriver(TransportType driverType, in NetworkDriverStore.NetworkDriverInstance driverInstance)
    Parameters
    Type Name Description
    TransportType driverType

    Driver type

    NetworkDriverStore.NetworkDriverInstance driverInstance

    Instance of driver

    Returns
    Type Description
    int

    The assigned driver id

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if cannot register or the NetworkDriverStore is finalized.

    ScheduleFlushSendAllDrivers(JobHandle)

    Invoke ScheduleFlushSend(JobHandle) on all registered drivers in the store

    Declaration
    public JobHandle ScheduleFlushSendAllDrivers(JobHandle dependency)
    Parameters
    Type Name Description
    JobHandle dependency

    A job handle whom all flush jobs depend upon

    Returns
    Type Description
    JobHandle

    The combined handle of all the scheduled jobs.

    In This Article
    Back to top
    Copyright © 2025 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)