Skip to main content

RealtimeModel

RealtimeModel

A model that represents a set of data to store in a room datastore.

Events

ownerIDSelfDidChange

event Action<RealtimeModel, int> ownerIDSelfDidChange

Dispatched when the ownerIDSelf value changes.

Properties

isFreshModel

bool isFreshModel { get; }

True if this model was just locally created. This flag can be used to apply component settings or initial values to a newly instantiated model.

hasMetaModel

bool hasMetaModel { get; }

True if the model has a meta-model. A meta-model is required for a client to take ownership of a model. You can add a meta-model to a custom model with the `createMetaModel` flag on the `RealtimeModel` attribute.

preventOwnershipTakeover

bool preventOwnershipTakeover { get; set; }

If true, the model owner must clear ownership before another client can request it.

isPersistent

bool isPersistent { get; }

If true, the object will persist after all clients leave the room.

destroyWhenLastClientLeaves

bool destroyWhenLastClientLeaves { get; set; }

If true, the model is destroyed when the last client in the room leaves.

destroyWhenOwnerLeaves

bool destroyWhenOwnerLeaves { get; set; }

If true, the model is destroyed when the owner of the model leaves the room.

room

Room room { get; }

The room managing this model, or null if this model is disconnected.

isRoomConnected

bool isRoomConnected { get; }

True if a room is set on this model and the room is connected.

ownerIDSelf

int ownerIDSelf { get; }

The client ID of the model owner. If the model is unowned, this returns -1.

ownerIDInHierarchy

int ownerIDInHierarchy { get; }

The client ID of the model in its hierarchy. This is the furthest owned ancestor without owned ancestors. If the model and all of its ancestors are unowned, this returns -1.

isUnownedSelf

bool isUnownedSelf { get; }

True if this model is not owned by any client.

isUnownedInHierarchy

bool isUnownedInHierarchy { get; }

True if this model and all of its parent models are not owned by any client.

isOwnedRemotelySelf

bool isOwnedRemotelySelf { get; }

True if this model is owned by a remote client.

isOwnedRemotelyInHierarchy

bool isOwnedRemotelyInHierarchy { get; }

True if this model or any of its parents are owned remotely.

isOwnedLocallySelf

bool isOwnedLocallySelf { get; }

True if this model is owned by the local client.

isOwnedLocallyInHierarchy

bool isOwnedLocallyInHierarchy { get; }

True if this model or any of its parents are owned locally.

Methods

RequestOwnership

void RequestOwnership(bool sendRedundantUpdates = false)

Request ownership of the model. This has no effect if the model has no meta-model. This will throw an exception if the model is not part of a connected room, as it requires the local clientID.

  • sendRedundantUpdates:If true, send the ownership update even if the model is already owned by the local client. This might send redundant updates but is useful if you expect contention. This does not circumvent the "Prevent Ownership Takeover" lifetime flag if it applies.
  • SetOwnership

    void SetOwnership(int ownerID, bool sendRedundantUpdates = false)

    Set ownership of the model to a specific client. This has no effect if the model has no meta-model.

  • ownerID:The client ID of the new owner.
  • sendRedundantUpdates:If true, send the ownership update even if the model is already owned by the specified ownerID. This might send redundant updates but is useful if you expect contention. This does not circumvent the "Prevent Ownership Takeover" lifetime flag if it applies.
  • ClearOwnership

    void ClearOwnership(bool sendRedundantUpdates = false)

    Clear ownership of the model.

  • sendRedundantUpdates:If true, send the ownership update even if the model is already unowned. This might send redundant updates but is useful if you expect contention. This does not circumvent the "Prevent Ownership Takeover" lifetime flag if it applies.