Skip to main content

Realtime

Realtime

Realtime manages a Room object and synchronizes its datastore to RealtimeViews and RealtimeComponents in the scene.

Static Properties

instances

IReadOnlyCollection<Realtime> instances { get; }

All of the Realtime instances currently loaded in scenes.

Static Methods

Instantiate

GameObject Instantiate(string prefabName, InstantiateOptions? options)

Instantiates a realtime prefab in the scene on all clients.

The fully instantiated game object. All RealtimeViews and RealtimeComponents, along with their models will be initialized and ready for use immediately.

  • prefabName:The name of the prefab to instantiate. The prefab must contain a RealtimeView on the root and it must live within a Resources folder or Unity will not be able to locate it on other clients.
  • options:Used to override the default ownership / lifetime settings for the object or to use a specific instance of Realtime when multiple instances are available in the scene.
  • Instantiate

    GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation, InstantiateOptions? options)

    Instantiates a realtime prefab in the scene on all clients.

    The fully instantiated game object. All RealtimeViews and RealtimeComponents, along with their models will be initialized and ready for use immediately.

  • prefabName:The name of the prefab to instantiate. The prefab must contain a RealtimeView on the root and it must live within a Resources folder or Unity will not be able to locate it on other clients.
  • options:Used to override the default ownership / lifetime settings for the object or to use a specific instance of Realtime when multiple instances are available in the scene.
  • Destroy

    void Destroy(GameObject gameObject)

    Destroys a realtime prefab on all clients.

    This method must be used instead of GameObject.Destroy(). It can only be used with GameObjects that were instantiated with Realtime.Instantiate().

  • gameObject:The game object to destroy.
  • Destroy

    void Destroy(RealtimeView realtimeView)

    Destroys a realtime prefab on all clients.

    This method must be used instead of GameObject.Destroy(). It can only be used with GameObjects that were instantiated with Realtime.Instantiate().

  • gameObject:The game object to destroy.
  • Events

    didConnectToRoom

    event RealtimeEvent didConnectToRoom

    An event that is fired when Realtime is connected to a room and all realtime prefabs and realtime views in the scene have been successfully connected to the datastore.

    didDisconnectFromRoom

    event RealtimeEvent didDisconnectFromRoom

    An event that is fired when Realtime is disconnected from a room.

    Properties

    roomToJoinOnStart

    string roomToJoinOnStart { get; }

    The name of the room to join on start if one was configured in the inspector.

    This setting can only be configured in the editor inspector. If you'd like to change this name at runtime, disable join room on start, and use the Connect() method on Realtime instead.

    joinRoomOnStart

    bool joinRoomOnStart { get; }

    A boolean indicating whether Realtime will try to automatically connect on Start().

    This setting can only be configured in the editor inspector. If you'd like to change this name at runtime, disable join room on start, and use the Connect() method on Realtime instead.

    normcoreAppSettings

    NormcoreAppSettings normcoreAppSettings { get; set; }

    The app settings object reference used when Realtime connects. Changing this while the Realtime instance is connected will not have any effect until the next time it connects.

    room

    Room room { get; set; }

    connecting

    bool connecting { get; }

    True if this Realtime instance is in the process of connecting or initializing its views.

    connected

    bool connected { get; }

    True if this Realtime instance is connected and its views are initialized.

    disconnected

    bool disconnected { get; }

    True if this Realtime instance is not connected or in an error state.

    clientID

    int clientID { get; }

    The local clientID of this Realtime instance.

    roomTime

    double roomTime { get; }

    The server time on this frame. This value has latency from the server removed.

    ping

    float ping { get; }

    The local client's last known ping with the server in milliseconds.

    Methods

    Connect

    void Connect(string roomName, RealtimeModel roomModel)

    Connect to a room.

  • roomName:The name of the room to connect to. All clients that connect to the same room name will end up on the same room server. Names must be less than 512 characters long.
  • roomModel:An optional RealtimeModel to use as the root model in the datastore.
  • Connect

    void Connect(string roomName, ConnectOptions connectOptions = null)

    Connect to a room.

  • roomName:The name of the room to connect to. All clients that connect to the same room name will end up on the same room server. Names must be less than 512 characters long.
  • roomModel:An optional RealtimeModel to use as the root model in the datastore.
  • Disconnect

    void Disconnect()

    Disconnect from a room.