Skip to main content

RealtimeDictionary<TValue>

RealtimeDictionary<TValue>

RealtimeDictionary is a special model type that represents an dictionary of models. This collection can be modified by multiple clients simultaneously without introducing datastore conflicts. All updates are applied instantly and are rolled back if rejected by the server (due to ownership). Adding or removing items sends the minimal amount of information to the server in order to perform the update on all clients. The whole collection is not sent every time.

Events

modelAdded

event ModelAdded<TValue> modelAdded

An event that fires when a model is added locally or remotely.

modelReplaced

event ModelReplaced<TValue> modelReplaced

An event that fires when a model is replaced locally or remotely.

A model is considered replaced (as opposed to removed and added) if a new model is added that overwrites an existing model under the same key.

modelRemoved

event ModelRemoved<TValue> modelRemoved

An event that fires when a model is removed locally or remotely.

Properties

Item

TValue Item { get; set; }

Access a model for a specific key.

  • key:The key of the model.
  • Count

    int Count { get; }

    The number of models currently stored in the collection.

    Methods

    Add

    void Add(uint key, TValue value)

    Add a model to the collection.

  • key:The key to store the model under
  • value:The model to store in the collection
  • Remove

    bool Remove(uint key)

    Remove a model from the collection.

    A boolean to indicate whether the key was contained within the collection.

  • key:The key of the model to remove
  • GetEnumerator

    IEnumerator<KeyValuePair<uint, TValue>> GetEnumerator()

    TryGetValue

    bool TryGetValue(uint key, TValue& value)

    Attempt to retrieve a value from the collection.

    This method will not throw an exception if the key is not found.

    A boolean indicating whether the key was found within the collection.

  • key:The key of the model to fetch.
  • value:The model if one is found, otherwise null.
  • ContainsKey

    bool ContainsKey(uint key)

    Check if a key exists within the collection.

    A boolean indicating whether the key was found within the collection.

  • key:The key to search for.
  • ContainsValue

    bool ContainsValue(TValue value)

    Check if a model instance is contained in the collection.

    This method is very slow! If you need high performance value searching, you should use the added/replaced/removed events to mirror this collection to a faster collection type.

    A boolean indicating whether the value was found within the collection.

  • value:The model instance to look for.
  • GetCollectionTypeID

    uint GetCollectionTypeID()