is there a problem if 2 different scripts use the same realtime model
is there a problem if 2 different scripts use the same realtime model?
4 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:
----------------------
If two different scripts use the same RealtimeModel instance, there is no inherent problem as long as both scripts are designed to work with that model and properly synchronize their state. In Normcore, a RealtimeModel represents a collection of states to synchronize, and multiple RealtimeComponent subclasses can interact with the same model to keep different parts of your scene in sync. The key is that each RealtimeComponent should be responsible for synchronizing a specific part of your scene with the model, and any changes made to the model will be propagated to all clients.
However, you should be careful to avoid conflicting updates or logic errors. If both scripts try to modify the same properties on the model simultaneously, you may encounter unexpected behavior or race conditions. Normcore enforces ownership at the model level, so only the owning client can make changes to the model and its children, which helps prevent some conflicts, but good design is still important.
The documentation describes how RealtimeComponent subclasses keep a game object in sync with its corresponding RealtimeModel instance, and how changes are synchronized between clients. It is common for multiple components to interact with the same model, especially in complex objects, as long as their responsibilities are clearly defined and coordinated RealtimeComponent.
If you need to coordinate multiple scripts, consider using events or clear separation of concerns to avoid conflicts.
If you have a more specific scenario in mind, please provide details!
----------------------
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 me know how I did by reacting below.
no problem, you can reuse model scripts with as many different component scripts as you like e.g. an int model can be used for a score component and health component at the same time
ty!