docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NetworkDictionary<TKey, TValue>

    Event based NetworkVariable container for syncing Dictionaries

    Inheritance
    object
    NetworkDictionary<TKey, TValue>
    Implements
    IDictionary<TKey, TValue>
    ICollection<KeyValuePair<TKey, TValue>>
    IEnumerable<KeyValuePair<TKey, TValue>>
    IEnumerable
    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.Collections
    Assembly: Unity.Multiplayer.MLAPI.Runtime.dll
    Syntax
    public class NetworkDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, INetworkVariable
    Type Parameters
    Name Description
    TKey

    The type for the dictionary keys

    TValue

    The type for the dictionary values

    Constructors

    NetworkDictionary()

    Creates a NetworkDictionary with the default value and settings

    Declaration
    public NetworkDictionary()

    NetworkDictionary(NetworkVariableSettings)

    Creates a NetworkDictionary with the default value and custom settings

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

    The settings to use for the NetworkDictionary

    NetworkDictionary(NetworkVariableSettings, IDictionary<TKey, TValue>)

    Creates a NetworkDictionary with a custom value and custom settings

    Declaration
    public NetworkDictionary(NetworkVariableSettings settings, IDictionary<TKey, TValue> value)
    Parameters
    Type Name Description
    NetworkVariableSettings settings

    The settings to use for the NetworkDictionary

    IDictionary<TKey, TValue> value

    The initial value to use for the NetworkDictionary

    NetworkDictionary(IDictionary<TKey, TValue>)

    Creates a NetworkDictionary with a custom value and the default settings

    Declaration
    public NetworkDictionary(IDictionary<TKey, TValue> value)
    Parameters
    Type Name Description
    IDictionary<TKey, TValue> value

    The initial value to use for the NetworkDictionary

    Fields

    Settings

    The settings for this container

    Declaration
    public readonly NetworkVariableSettings Settings
    Field Value
    Type Description
    NetworkVariableSettings

    Properties

    Count

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

    IsReadOnly

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

    this[TKey]

    Declaration
    public TValue this[TKey key] { get; set; }
    Parameters
    Type Name Description
    TKey key
    Property Value
    Type Description
    TValue

    Keys

    Declaration
    public ICollection<TKey> Keys { get; }
    Property Value
    Type Description
    ICollection<TKey>

    LastSyncedTime

    Gets the last time the variable was synced

    Declaration
    public float LastSyncedTime { get; }
    Property Value
    Type Description
    float

    Values

    Declaration
    public ICollection<TValue> Values { get; }
    Property Value
    Type Description
    ICollection<TValue>

    Methods

    Add(KeyValuePair<TKey, TValue>)

    Declaration
    public void Add(KeyValuePair<TKey, TValue> item)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue> item

    Add(TKey, TValue)

    Declaration
    public void Add(TKey key, TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value

    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

    Clear()

    Declaration
    public void Clear()

    Contains(KeyValuePair<TKey, TValue>)

    Declaration
    public bool Contains(KeyValuePair<TKey, TValue> item)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue> item
    Returns
    Type Description
    bool

    ContainsKey(TKey)

    Declaration
    public bool ContainsKey(TKey key)
    Parameters
    Type Name Description
    TKey key
    Returns
    Type Description
    bool

    CopyTo(KeyValuePair<TKey, TValue>[], int)

    Declaration
    public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue>[] array
    int arrayIndex

    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

    GetEnumerator()

    Declaration
    public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
    Returns
    Type Description
    IEnumerator<KeyValuePair<TKey, TValue>>

    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 delta from the reader and applies them to the internal value

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

    The stream to read the delta from

    bool keepDirtyDelta

    Whether or not the delta should be kept as dirty or consumed

    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

    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

    Remove(KeyValuePair<TKey, TValue>)

    Declaration
    public bool Remove(KeyValuePair<TKey, TValue> item)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue> item
    Returns
    Type Description
    bool

    Remove(TKey)

    Declaration
    public bool Remove(TKey key)
    Parameters
    Type Name Description
    TKey key
    Returns
    Type Description
    bool

    ResetDirty()

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

    Declaration
    public void ResetDirty()

    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

    TryGetValue(TKey, out TValue)

    Declaration
    public bool TryGetValue(TKey key, out TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    Returns
    Type Description
    bool

    WriteDelta(Stream)

    Writes the dirty changes, that is, the changes since the variable was last dirty, to the writer

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

    The stream to write the dirty changes 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

    Events

    OnDictionaryChanged

    The callback to be invoked when the dictionary gets changed

    Declaration
    public event NetworkDictionary<TKey, TValue>.OnDictionaryChangedDelegate OnDictionaryChanged
    Event Type
    Type Description
    NetworkDictionary<TKey, TValue>.OnDictionaryChangedDelegate

    Implements

    IDictionary<TKey, TValue>
    ICollection<T>
    IEnumerable<T>
    IEnumerable
    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)