docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NetworkList<T>

    Event based NetworkVariable container for syncing Lists

    Inheritance
    object
    NetworkVariableBase
    NetworkList<T>
    Implements
    IDisposable
    Inherited Members
    NetworkVariableBase.GetBehaviour()
    NetworkVariableBase.Initialize(NetworkBehaviour)
    NetworkVariableBase.OnInitialize()
    NetworkVariableBase.SetUpdateTraits(NetworkVariableUpdateTraits)
    NetworkVariableBase.ExceedsDirtinessThreshold()
    NetworkVariableBase.DefaultReadPerm
    NetworkVariableBase.DefaultWritePerm
    NetworkVariableBase.Name
    NetworkVariableBase.ReadPerm
    NetworkVariableBase.WritePerm
    NetworkVariableBase.SetDirty(bool)
    NetworkVariableBase.MarkNetworkBehaviourDirty()
    NetworkVariableBase.CanClientRead(ulong)
    NetworkVariableBase.CanClientWrite(ulong)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Netcode
    Assembly: Unity.Netcode.Runtime.dll
    Syntax
    [GenerateSerializationForGenericParameter(0)]
    public class NetworkList<T> : NetworkVariableBase, IDisposable where T : unmanaged, IEquatable<T>
    Type Parameters
    Name Description
    T

    The type for the list

    Constructors

    NetworkList()

    Constructor method for NetworkList<T>

    Declaration
    public NetworkList()

    NetworkList(IEnumerable<T>, NetworkVariableReadPermission, NetworkVariableWritePermission)

    Event based NetworkVariable container for syncing Lists

    Declaration
    public NetworkList(IEnumerable<T> values = null, NetworkVariableReadPermission readPerm = NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission writePerm = NetworkVariableWritePermission.Server)
    Parameters
    Type Name Description
    IEnumerable<T> values

    An optional collection of initial values to populate the list. If null, the list will start empty.

    NetworkVariableReadPermission readPerm

    The read permission level for the network list. Determines who can read the list (e.g., server-only or everyone). Default is defined by DefaultReadPerm

    NetworkVariableWritePermission writePerm

    The write permission level for the network list. Determines who can modify the list (e.g., server-only or specific clients). Default is defined by DefaultWritePerm.

    Properties

    Count

    Gets the number of elements contained in the NetworkList<T>.

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

    this[int]

    Gets or sets the element at the specified index in the NetworkList<T>.

    Declaration
    public T this[int index] { get; set; }
    Parameters
    Type Name Description
    int index

    The zero-based index of the element to get or set.

    Property Value
    Type Description
    T

    The element at the specified index.

    Remarks

    This method checks for write permissions before setting the value.

    LastModifiedTick

    This method should not be used. It is left over from a previous interface

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

    Methods

    Add(T)

    Adds an item to the end of the NetworkList<T>.

    Declaration
    public void Add(T item)
    Parameters
    Type Name Description
    T item

    The item to be added to the list.

    Remarks

    This method checks for write permissions before adding the item.

    Clear()

    Removes all items from the NetworkList<T>.

    Declaration
    public void Clear()
    Remarks

    This method checks for write permissions before clearing the list.

    Contains(T)

    Determines whether the NetworkList<T> contains a specific value.

    Declaration
    public bool Contains(T item)
    Parameters
    Type Name Description
    T item

    The object to locate in the NetworkList<T>.

    Returns
    Type Description
    bool

    true if the item is found in the NetworkList<T>; otherwise, false.

    Dispose()

    Overridden IDisposable implementation. CAUTION: If you derive from this class and override the Dispose() method, you must always invoke the base.Dispose() method!

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

    ~NetworkList()

    Finalizer that ensures proper cleanup of network list resources

    Declaration
    protected ~NetworkList()

    GetEnumerator()

    Returns an enumerator that iterates through the NetworkList<T>.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    IEnumerator<T>

    An enumerator for the NetworkList<T>.

    IndexOf(T)

    Determines the index of a specific item in the NetworkList<T>.

    Declaration
    public int IndexOf(T item)
    Parameters
    Type Name Description
    T item

    The object to remove from the list.

    Returns
    Type Description
    int

    The index of the item if found in the list; otherwise, -1.

    Insert(int, T)

    Inserts item to the NetworkList<T> at the specified index.

    Declaration
    public void Insert(int index, T item)
    Parameters
    Type Name Description
    int index

    The index at which the item should be inserted.

    T item

    The item to insert.

    Remarks

    This method checks for write permissions before inserting the item.

    IsDirty()

    Gets Whether or not the container is dirty

    Declaration
    public override bool IsDirty()
    Returns
    Type Description
    bool

    Whether or not the container is dirty

    Overrides
    NetworkVariableBase.IsDirty()

    ReadDelta(FastBufferReader, bool)

    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

    bool keepDirtyDelta

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

    Overrides
    NetworkVariableBase.ReadDelta(FastBufferReader, bool)

    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)

    Remove(T)

    Removes the first occurrence of a specific object from the NetworkList.

    Declaration
    public bool Remove(T item)
    Parameters
    Type Name Description
    T item

    The object to remove from the list.

    Returns
    Type Description
    bool

    true if the item was successfully removed from the list; otherwise, false.

    Remarks

    This method checks for write permissions before removing the item.

    RemoveAt(int)

    Removes the NetworkList<T> item at the specified index.

    Declaration
    public void RemoveAt(int index)
    Parameters
    Type Name Description
    int index

    The index of the element to remove.

    Remarks

    This method checks for write permissions before removing the item.

    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)

    Events

    OnListChanged

    Creates A NetworkList/>

    Declaration
    public event NetworkList<T>.OnListChangedDelegate OnListChanged
    Event Type
    Type Description
    NetworkList<T>.OnListChangedDelegate

    Implements

    IDisposable
    In This Article
    • Constructors
      • NetworkList()
      • NetworkList(IEnumerable<T>, NetworkVariableReadPermission, NetworkVariableWritePermission)
    • Properties
      • Count
      • this[int]
      • LastModifiedTick
    • Methods
      • Add(T)
      • Clear()
      • Contains(T)
      • Dispose()
      • ~NetworkList()
      • GetEnumerator()
      • IndexOf(T)
      • Insert(int, T)
      • IsDirty()
      • ReadDelta(FastBufferReader, bool)
      • ReadField(FastBufferReader)
      • Remove(T)
      • RemoveAt(int)
      • ResetDirty()
      • WriteDelta(FastBufferWriter)
      • WriteField(FastBufferWriter)
    • Events
      • OnListChanged
    • Implements
    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)