docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NetworkVariable<T>

    A variable that can be synchronized over the network.

    Inheritance
    object
    NetworkVariable<T>
    NetworkVariableBool
    NetworkVariableByte
    NetworkVariableColor
    NetworkVariableColor32
    NetworkVariableDouble
    NetworkVariableFloat
    NetworkVariableInt
    NetworkVariableLong
    NetworkVariableQuaternion
    NetworkVariableRay
    NetworkVariableSByte
    NetworkVariableShort
    NetworkVariableString
    NetworkVariableUInt
    NetworkVariableULong
    NetworkVariableUShort
    NetworkVariableVector2
    NetworkVariableVector3
    NetworkVariableVector4
    Implements
    INetworkVariable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: MLAPI.NetworkVariable
    Assembly: Unity.Multiplayer.MLAPI.Runtime.dll
    Syntax
    [Serializable]
    public class NetworkVariable<T> : INetworkVariable
    Type Parameters
    Name Description
    T

    Constructors

    NetworkVariable()

    Creates a NetworkVariable with the default value and settings

    Declaration
    public NetworkVariable()

    NetworkVariable(NetworkVariableSettings)

    Creates a NetworkVariable with the default value and custom settings

    Declaration
    public NetworkVariable(NetworkVariableSettings settings)
    Parameters
    Type Name Description
    NetworkVariableSettings settings

    The settings to use for the NetworkVariable

    NetworkVariable(NetworkVariableSettings, T)

    Creates a NetworkVariable with a custom value and custom settings

    Declaration
    public NetworkVariable(NetworkVariableSettings settings, T value)
    Parameters
    Type Name Description
    NetworkVariableSettings settings

    The settings to use for the NetworkVariable

    T value

    The initial value to use for the NetworkVariable

    NetworkVariable(T)

    Creates a NetworkVariable with a custom value and the default settings

    Declaration
    public NetworkVariable(T value)
    Parameters
    Type Name Description
    T value

    The initial value to use for the NetworkVariable

    Fields

    OnValueChanged

    The callback to be invoked when the value gets changed

    Declaration
    public NetworkVariable<T>.OnValueChangedDelegate OnValueChanged
    Field Value
    Type Description
    NetworkVariable<T>.OnValueChangedDelegate

    Settings

    The settings for this var

    Declaration
    public readonly NetworkVariableSettings Settings
    Field Value
    Type Description
    NetworkVariableSettings

    Properties

    LocalTick

    The last time the variable was written to locally

    Declaration
    public ushort LocalTick { get; }
    Property Value
    Type Description
    ushort

    RemoteTick

    The last time the variable was written to remotely. Uses the remote timescale

    Declaration
    public ushort RemoteTick { get; }
    Property Value
    Type Description
    ushort

    Value

    The value of the NetworkVariable container

    Declaration
    public T Value { get; set; }
    Property Value
    Type Description
    T

    Methods

    CanClientRead(ulong)

    Gets Whether or not a specific client can read to the varaible

    Declaration
    public bool CanClientRead(ulong clientId)
    Parameters
    Type Name Description
    ulong clientId

    The clientId of the remote client

    Returns
    Type Description
    bool

    Whether or not the client can read to the variable

    CanClientWrite(ulong)

    Gets Whether or not a specific client can write to the varaible

    Declaration
    public bool CanClientWrite(ulong clientId)
    Parameters
    Type Name Description
    ulong clientId

    The clientId of the remote client

    Returns
    Type Description
    bool

    Whether or not the client can write to the variable

    GetChannel()

    Returns the name of the channel to be used for syncing

    Declaration
    public NetworkChannel GetChannel()
    Returns
    Type Description
    NetworkChannel

    The name of the channel to be used for syncing

    IsDirty()

    Gets Whether or not the container is dirty

    Declaration
    public bool IsDirty()
    Returns
    Type Description
    bool

    Whether or not the container is dirty

    ReadDelta(Stream, bool, ushort, ushort)

    Reads value from the reader and applies it

    Declaration
    public void ReadDelta(Stream stream, bool keepDirtyDelta, ushort localTick, ushort remoteTick)
    Parameters
    Type Name Description
    Stream stream

    The stream to read the value from

    bool keepDirtyDelta

    Whether or not the container should keep the dirty delta, or mark the delta as consumed

    ushort localTick
    ushort remoteTick

    ReadField(Stream, ushort, ushort)

    Reads the complete state from the reader and applies it

    Declaration
    public void ReadField(Stream stream, ushort localTick, ushort remoteTick)
    Parameters
    Type Name Description
    Stream stream

    The stream to read the state from

    ushort localTick

    The local network tick at which this var was written, on the machine it was written

    ushort remoteTick

    The remote network tick at which this var was sent by the host

    ResetDirty()

    Resets the dirty state and marks the variable as synced / clean

    Declaration
    public void ResetDirty()

    SetDirty(bool)

    Sets whether or not the variable needs to be delta synced

    Declaration
    public void SetDirty(bool isDirty)
    Parameters
    Type Name Description
    bool isDirty

    SetNetworkBehaviour(NetworkBehaviour)

    Sets NetworkBehaviour the container belongs to.

    Declaration
    public void SetNetworkBehaviour(NetworkBehaviour behaviour)
    Parameters
    Type Name Description
    NetworkBehaviour behaviour

    The behaviour the container behaves to

    WriteDelta(Stream)

    Writes the variable to the writer

    Declaration
    public void WriteDelta(Stream stream)
    Parameters
    Type Name Description
    Stream stream

    The stream to write the value to

    WriteField(Stream)

    Writes the complete state of the variable to the writer

    Declaration
    public void WriteField(Stream stream)
    Parameters
    Type Name Description
    Stream stream

    The stream to write the state to

    Implements

    INetworkVariable
    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)