Syncing existing data in a model to a new joiner
When a new person joins and connects to Realtime, I want them to be able to read data from an existing RealtimeDictionary that already has data inside a RealtimeComponent. Where do I do this? In OnRealtimeModelReplaced? If so, how do I access the existing data / when do I know that the local sync has the remote data?
2 Replies
Hi @khoi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
You're asking about the right approach for syncing existing data in a RealtimeDictionary to new users joining a Normcore session. This is a common scenario when building multiplayer VR applications.
Yes,
OnRealtimeModelReplaced()
is exactly where you should handle this. When a new client joins a room, Normcore automatically synchronizes the existing datastore state to them. The model passed to OnRealtimeModelReplaced()
will already contain all the data that exists on the server, including any RealtimeDictionary contents.
Here's how you can access the existing data in a RealtimeDictionary:
The key point is that by the time OnRealtimeModelReplaced()
is called with a non-fresh model, that model already contains all the synchronized data from the server. You don't need to wait for anything else - you can immediately iterate through the dictionary and process its contents.
As explained in the Datastore documentation, Normcore handles all the synchronization for you:
When another client makes a change to its datastore, the change is sent to the room server, which will perform validation or transformation of the data before relaying it to all clients.For more information about collections in Normcore, you can refer to the Collections documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@412870643533479936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.