OnRealtimeModelReplaced is not being called
when i run SetStarted(true), i only get "set" in the console. i tried re-adding the component and it didnt work.
3 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:
----------------------
The
OnRealtimeModelReplaced
method is called when you connect to the room and the model is set by Realtime. If this method is not being called, it could be due to several reasons:
1. The model was instantiated with Unity’s Instantiate API (Instantiate()
or GameObject.Instantiate()
) instead of Normcore’s Realtime.Instantiate()
. If you're passing a prefab reference instead of a prefab string, then you're using the wrong one. Make sure to call Realtime.Instantiate(prefabName)
.
2. The prefab in Unity is corrupt, so the RealtimeComponent does not appear in the component list on the RealtimeView, and models are not created for those components.
3. A RealtimeView parent/child relationship is not saved correctly by Unity. In these cases, the RealtimeView child doesn't appear in the list of child views on the parent RealtimeView inspector.
4. You're using RealtimeComponent
(rather than RealtimeComponent<ModelType>
) and the model setter hasn’t been correctly implemented. This can be because the model setter didn’t save the value of the model or because it was not named model.
5. You're checking the model property inside of Awake()
(or, for scene RealtimeViews, inside of Start()
). To fix this:
- If using RealtimeComponent<ModelType>
, move the initialization logic inside of your OnRealtimeModelReplaced()
method.
- If using the legacy RealtimeComponent
class, move the initialization logic into your model setter.
Also, if your custom RealtimeComponent isn't syncing, it's possible that you added your custom component to a game object before it was converted to a RealtimeComponent subclass. To verify this, look at the RealtimeView's list of components and make sure you see your custom component in the list. If you don't see it, or a RealtimeView has not been created for you automatically, try removing the component and re-adding it to your game object. This will tell Unity to automatically create a RealtimeView and add your RealtimeComponent subclass to its component list.
Please refer to the following documentation for more details:
- RealtimeComponent's model remain null (https://normcore.io/documentation/realtime/common-questions#why-would-a-realtimecomponents-model-remain-null)
- My custom RealtimeComponent isn't syncing (https://normcore.io/documentation/realtime/synchronizing-custom-data#my-custom-realtimecomponent-isnt-syncing-and-onrealtimemodelreplaced-doesnt-get-called)
----------------------
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 us know how it did by reacting below
make sure you register for the change event before making the change