OnRealtimeModelReplaced what happens if I don't initialize fresh model?
In OnRealtimeModelReplaced, what will happen if I don't initialize the values of a fresh model?
if (currentModel != null)
{
if (currentModel.isFreshModel)
{
Debug.LogError("FRESH MODEL");
currentModel.leftIndexTriggerNormalized = LeftIndexTriggerNormalized;
currentModel.rightIndexTriggerNormalized = RightIndexTriggerNormalized;
Eg, what if I leave a bunch of currentModel.[FIELD] values uninitialized?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:
----------------------
If you don't initialize the values of a fresh model in
OnRealtimeModelReplaced()
, those fields will retain their default values, which depends on their data type (e.g., 0 for numeric types, null for reference types, etc.). This means other clients connecting to the room will see these default values rather than any specific initial state you might want to set.
The isFreshModel
property is specifically designed to help you identify when you should set initial values on a model. As explained in the Normcore documentation:
This pattern is recommended in the RealtimeComponent documentation for synchronizing unique default values.
If you don't initialize values for a fresh model:
1. The model will use default values for all uninitialized fields
2. These default values will be synchronized to all clients
3. You might miss the opportunity to set important initial state that reflects your game object's current configuration
For example, in the ColorSync example, they initialize the model's color with the current mesh renderer color when it's a fresh model:
Without this initialization, the color would default to whatever the default value for the Color type is, rather than matching the actual color of your object.
----------------------
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.