khoi
khoi2w ago

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
kapa.ai
kapa.ai2w ago
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:
if (currentModel.isFreshModel) {
// Set initial values here
currentModel.startPosition = transform.localPosition;
}
if (currentModel.isFreshModel) {
// Set initial values here
currentModel.startPosition = transform.localPosition;
}
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:
if (currentModel.isFreshModel)
currentModel.color = _meshRenderer.material.color;
if (currentModel.isFreshModel)
currentModel.color = _meshRenderer.material.color;
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: ----------------------
kapa.ai
kapa.ai2w ago
<@412870643533479936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?