Should a realtime custom component that is changing every frame be handled any differently?
Or should you still just use a didchange event even if it is changing every frame all the time?
5 Replies
Hi @cryptomax. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In NormalVR, the RealtimeComponent subclass is responsible for keeping a specific part of your scene in sync. When the game object changes, the component updates the model, and when the model changes, the component updates the game object to match. This is done through a didChange event that fires whenever the model changes either locally or remotely. This event is used to update the scene to match the model.
However, if your custom component is changing every frame, you might want to consider the performance implications. The documentation suggests that continuously calling an update method from
Update()
to make sure the renderer matches the model every frame might not be the best approach. This is because it's susceptible to the project's Script Execution Order which can cause updates to be delayed by a frame. Instead, registering for an event from the model that fires whenever it changes locally or by a remote client is recommended. This event can then be used to call your update method.
Here's an example of how you can register for a change event:
In this example, the ColorDidChange
method is called whenever the model's color
property changes, updating the mesh renderer accordingly.
So, even if your component is changing every frame, using a didChange event is still a recommended approach. However, you should always consider the performance implications and test your application thoroughly to ensure it performs as expected.
Sources:
- RealtimeComponent (https://normcore.io/documentation/realtime/realtimecomponent)
- Creating a RealtimeComponent subclass (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:
----------------------<@401986039964631060> kapa.ai is still learning and improving, please let us know how it did by reacting below
by default I think normcore sends 20 times per second so remote clients probably wont get new data every single frame but really it's up to you which you prefer
for local client changes that's really up to you
hmmm so 20 didchange events per second is probably actually better off than an Update fetch and set
yeah i'm talking about the synced changes
Solution
did change is probably better then