docs.unity3d.com
    Show / Hide Table of Contents

    Class NetworkVariable<T>

    A variable that can be synchronized over the network.

    Inheritance
    Object
    NetworkVariableBase
    NetworkVariable<T>
    NetworkVariableMiddleclass<TMiddleclassName>
    Inherited Members
    NetworkVariableBase.GetBehaviour()
    NetworkVariableBase.Initialize(NetworkBehaviour)
    NetworkVariableBase.DefaultReadPerm
    NetworkVariableBase.DefaultWritePerm
    NetworkVariableBase.Name
    NetworkVariableBase.ReadPerm
    NetworkVariableBase.WritePerm
    NetworkVariableBase.SetDirty(Boolean)
    NetworkVariableBase.CanClientRead(UInt64)
    NetworkVariableBase.CanClientWrite(UInt64)
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Netcode
    Syntax
    [Serializable]
    public class NetworkVariable<T> : NetworkVariableBase, IDisposable
    Type Parameters
    Name Description
    T

    the unmanaged type for NetworkVariable<T>

    Constructors

    NetworkVariable(T, NetworkVariableReadPermission, NetworkVariableWritePermission)

    Constructor for NetworkVariable<T>

    Declaration
    public NetworkVariable(T value = null, NetworkVariableReadPermission readPerm = NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission writePerm = NetworkVariableWritePermission.Server)
    Parameters
    Type Name Description
    T value

    initial value set that is of type T

    NetworkVariableReadPermission readPerm

    the NetworkVariableReadPermission for this NetworkVariable<T>

    NetworkVariableWritePermission writePerm

    the NetworkVariableWritePermission for this NetworkVariable<T>

    Fields

    OnValueChanged

    The callback to be invoked when the value gets changed

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

    Properties

    Value

    The value of the NetworkVariable container

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

    Methods

    Dispose()

    Declaration
    public override void Dispose()
    Overrides
    NetworkVariableBase.Dispose()

    Finalize()

    Declaration
    protected void Finalize()

    IsDirty()

    Gets Whether or not the container is dirty

    Declaration
    public override bool IsDirty()
    Returns
    Type Description
    Boolean

    Whether or not the container is dirty

    Overrides
    NetworkVariableBase.IsDirty()

    ReadDelta(FastBufferReader, Boolean)

    Reads value from the reader and applies it

    Declaration
    public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
    Parameters
    Type Name Description
    FastBufferReader reader

    The stream to read the value from

    Boolean keepDirtyDelta

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

    Overrides
    NetworkVariableBase.ReadDelta(FastBufferReader, Boolean)

    ReadField(FastBufferReader)

    Reads the complete state from the reader and applies it

    Declaration
    public override void ReadField(FastBufferReader reader)
    Parameters
    Type Name Description
    FastBufferReader reader

    The stream to read the state from

    Overrides
    NetworkVariableBase.ReadField(FastBufferReader)

    ResetDirty()

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

    Declaration
    public override void ResetDirty()
    Overrides
    NetworkVariableBase.ResetDirty()

    WriteDelta(FastBufferWriter)

    Writes the variable to the writer

    Declaration
    public override void WriteDelta(FastBufferWriter writer)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The stream to write the value to

    Overrides
    NetworkVariableBase.WriteDelta(FastBufferWriter)

    WriteField(FastBufferWriter)

    Writes the complete state of the variable to the writer

    Declaration
    public override void WriteField(FastBufferWriter writer)
    Parameters
    Type Name Description
    FastBufferWriter writer

    The stream to write the state to

    Overrides
    NetworkVariableBase.WriteField(FastBufferWriter)
    In This Article
    • Constructors
      • NetworkVariable(T, NetworkVariableReadPermission, NetworkVariableWritePermission)
    • Fields
      • OnValueChanged
    • Properties
      • Value
    • Methods
      • Dispose()
      • Finalize()
      • IsDirty()
      • ReadDelta(FastBufferReader, Boolean)
      • ReadField(FastBufferReader)
      • ResetDirty()
      • WriteDelta(FastBufferWriter)
      • WriteField(FastBufferWriter)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023