beeeen
beeeen3mo ago

Is it better to have more variables per RealtimeComponent?

Say that I have 5 variables that I want to sync using a RealtimeComponent. Is it better to use 1 RealtimeComponent for all 5 of these variables or is it better to use 5 RealtimeComponents, each with 1 variable? Does it matter? My reasoning here is that every RealtimeComponent requires some overhead to create an id and an entry in the datastore. Therefore, if you have many variables that you have to sync, then it would make sense that having one RealtimeComponent to handle all those variables would reduce the overhead.
4 Replies
kapa.ai
kapa.ai3mo ago
Hi @beeeen. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The documentation does not provide a direct answer to your question. However, it does mention that each RealtimeComponent is responsible for keeping a specific part of your scene in sync, and it does this by storing the state it needs to synchronize in a RealtimeModel subclass. The model is automatically synchronized across all clients by Normcore, so all the RealtimeComponent needs to do is synchronize the scene and the model to match (source (https://normcore.io/documentation/realtime/realtimecomponent)). When creating a custom RealtimeComponent, you also need to create a model to put in the datastore. For example, if you're creating a RealtimeComponent that synchronizes the color of an object, you would create a script for the component and one for the model, such as ColorSync.cs and ColorSyncModel.cs respectively (source (https://normcore.io/documentation/realtime/synchronizing-custom-data)). Each property in the model has a unique ID used by Normcore to identify it when sending data to and from the server. The property ID needs to be unique, but only to this model. It does not have to be unique to the whole project (source (https://normcore.io/documentation/realtime/synchronizing-custom-data#propertyid)). Based on this information, it seems that you could use a single RealtimeComponent to handle multiple variables, as long as each variable is represented as a property in the associated model. However, the best approach may depend on the specifics of your application and how closely related the variables are. If the variables represent distinct aspects of your scene that could logically be separated, it might make sense to use separate RealtimeComponents for clarity and maintainability. Remember that you cannot add RealtimeComponents at runtime, as Normcore uses metadata on the prefab to connect RealtimeComponents on all clients (source (https://normcore.io/documentation/realtime/common-questions#can-i-add-realtimecomponents-at-runtime)). For more detailed advice tailored to your specific use case, you may want to consult the Normcore documentation or reach out to their support team. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@690217885540417680> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit3mo ago
the overhead is minimal but yes, fewer components are better
maxweisel
maxweisel3mo ago
there is zero benefit from a bandwidth standpoint. components do not have IDs that need to be created in the database. The same ID is sent for delta updates as well as the initial value set. Splitting it up just changes the ID value but doesn’t affect bandwidth. the only main performance difference is Unity having to instantiate an extra monobehaviour and an extra loop pass at serialization time