Order in which player is brought up to speed with realtime models.
When a player connects to a session. I have a setup where the realtime avatar manager generates them a player prefab. But I was wondering if by the time their player avatar is created, are they already up to speed with the sync data in the models? is there a distinct order of operations that occurs regarding the model realtime properties and the player connecting to the room.
3 Replies
Hi @RonJames. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
When a player connects to a Normcore room, there is a well-defined order of operations that ensures the client is brought up to speed with the current state of all realtime models before their avatar prefab is instantiated and used.
Order of Operations:
1. Connection and Datastore Sync:
When a client connects to a room, Normcore first synchronizes the entire datastore from the server to the client. This includes all RealtimeModel objects and their current state. The server sends a complete snapshot of the datastore to the new client, ensuring they have the latest state before proceeding. Only after this initial sync does the client begin to receive delta updates for ongoing changes in the room. This guarantees that the client is fully up to date with all model data before any prefabs are instantiated or used in the scene.
Unity Client Architecture 2. Prefab Instantiation:
For avatar prefabs (or any realtime prefab), instantiation is typically triggered after the connection is established. The RealtimeAvatarManager listens for the connection event and then instantiates the local avatar prefab. When this happens, all RealtimeViews and RealtimeComponents on the prefab are immediately initialized with their models, which are already populated with the latest synchronized data from the datastore.
RealtimeAvatarManager Reference
Realtime Prefab Instantiation 3. Model Availability:
By the time the avatar prefab is created, the models and their properties are already up to date. The documentation specifies that for prefabs instantiated with Realtime.Instantiate(), all views and components are initialized with their models and are ready to work with by the time Start() is called on any script on the prefab.
RealtimeView Common Questions Summary:
Yes, by the time the player’s avatar prefab is created (via RealtimeAvatarManager or otherwise), the client is already fully synchronized with the current state of all realtime models in the room. The order is: datastore sync → prefab instantiation → model initialization. This ensures that any logic in your avatar or player prefab scripts will have access to the latest model data as soon as they start running. If you need to perform logic that depends on the models being up to date, you can safely do so in Start() or in the OnRealtimeModelReplaced() method of your RealtimeComponent subclasses, as the models will be fully initialized at that point. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
When a client connects to a room, Normcore first synchronizes the entire datastore from the server to the client. This includes all RealtimeModel objects and their current state. The server sends a complete snapshot of the datastore to the new client, ensuring they have the latest state before proceeding. Only after this initial sync does the client begin to receive delta updates for ongoing changes in the room. This guarantees that the client is fully up to date with all model data before any prefabs are instantiated or used in the scene.
Unity Client Architecture 2. Prefab Instantiation:
For avatar prefabs (or any realtime prefab), instantiation is typically triggered after the connection is established. The RealtimeAvatarManager listens for the connection event and then instantiates the local avatar prefab. When this happens, all RealtimeViews and RealtimeComponents on the prefab are immediately initialized with their models, which are already populated with the latest synchronized data from the datastore.
RealtimeAvatarManager Reference
Realtime Prefab Instantiation 3. Model Availability:
By the time the avatar prefab is created, the models and their properties are already up to date. The documentation specifies that for prefabs instantiated with Realtime.Instantiate(), all views and components are initialized with their models and are ready to work with by the time Start() is called on any script on the prefab.
RealtimeView Common Questions Summary:
Yes, by the time the player’s avatar prefab is created (via RealtimeAvatarManager or otherwise), the client is already fully synchronized with the current state of all realtime models in the room. The order is: datastore sync → prefab instantiation → model initialization. This ensures that any logic in your avatar or player prefab scripts will have access to the latest model data as soon as they start running. If you need to perform logic that depends on the models being up to date, you can safely do so in Start() or in the OnRealtimeModelReplaced() method of your RealtimeComponent subclasses, as the models will be fully initialized at that point. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@378869779668140042> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
if you subscribe to Realtime.didConnectToRoom, it fires after everything is in sync and all prefabs have been instantiated