custom sync question
what is this for and is it required to have it in your script?
7 Replies
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
OnRealtimeModelReplaced
method is part of the RealtimeComponent
class in NormalVR's Normcore. It is called when a RealtimeComponent
is first created and starts with no model. Normcore populates it once we have successfully connected to the server (or instantly, if we're already connected) and calls OnRealtimeModelReplaced()
to provide us with a copy of it. If this RealtimeComponent
was previously mapped to a different model (e.g., when switching rooms), it will provide a reference to the previous model in order to allow your component to unregister from events.
In the provided code, the method is used to synchronize the color of a game object with the model. If the model is fresh (i.e., it's a model for an object that just got created), it populates it with the color of the MeshRenderer
. It then updates the MeshRenderer
to match the color stored on the model. Finally, it registers for the colorDidChange
event that calls the ColorDidChange
method whenever the model's color
property changes. This way, if the color changes later, the method will be notified so it can update the mesh renderer.
This method is not necessarily required in every script, but it is crucial when you want to synchronize custom data in your Unity application using custom realtime components in Normcore. If you're not using Normcore or not synchronizing custom data, you might not need this method.
Here is the code you asked about:
You can find more information about this in the Normcore documentation (https://normcore.io/documentation/realtime/synchronizing-custom-data#creating-a-realtimecomponent-subclass).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below
you only need that if you want change events
wdym change events?
this bit: currentModel.colorDidChange += ColorDidChange;
when someone updates the model this method is called
i think i understand
its 2 am so ill read it again tomorrow
but ill add it either way
if it's something that changes every frame like position you can just poll the model, or if it only appears on-demand like looking at a leaderboard you can also just read the data when you need it.
Change events are for more time critical things like a synced event or particle effect.