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.

    didDisconnectFromRoomWithEvent

    event RealtimeDisconnectEvent didDisconnectFromRoomWithEvent

    An event that is fired when Realtime is disconnected from a room. Provides detailed information about the disconnect.

    Properties

    joinRoomOnStartOptions

    JoinRoomOnStartOptions joinRoomOnStartOptions { get; }

    The options that configure if and how [Normal.Realtime.Realtime](Normal.Realtime#realtime) will connect on Start().

    These settings can only be configured in the editor inspector. If you'd like more control over joining rooms at runtime, disable "Join Room On Start" and use the or methods 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.

    roomName

    string roomName { get; }

    The name of the room.

    roomTime

    double roomTime { get; }

    The server time on this frame in unix epoch time format (seconds since 00:00:00 UTC on January 1, 1970).

    This value can be used to drive animations and is backed by a monotonic clock with sub-millisecond precision. This value has latency from the server removed.

    roomDateTime

    DateTime? roomDateTime { get; }

    The server date and time on this frame (UTC).

    This value can be used to drive day/night cycles, for example. It is directly derived from . Will be null when the room is not yet in the state.

    ping

    float ping { get; }

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

    region

    RegionMetadata? region { get; }

    The region metadata for the current room server.

    Methods

    GetRegionsListAsync

    Task<GetRegionsListResponse> GetRegionsListAsync(GetRegionsListOptions options = null, CancellationToken cancellationToken = null)

    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.
  • ConnectDirectlyToQuickmatchRoom

    void ConnectDirectlyToQuickmatchRoom(string roomGroupName, string roomCode, ConnectOptions connectOptions = null)

    ConnectToNextAvailableQuickmatchRoom

    void ConnectToNextAvailableQuickmatchRoom(string roomGroupName, int capacity, ConnectOptions connectOptions = null)

    Disconnect

    void Disconnect()

    Disconnect from a room.