RealtimeView inside a scene
So I'm having this issue where I have a series of prefabs inside my scene which all have realtime models. They are multiple instances of the same prefab but are not instatiated. Rather hand placed and enabled after start in my game scene. I seem to be getting the error RealtimeView model is null. Was this view instantiated with GameObject.Instantiate instead of Realtime.Instantiate? Make sure you're passing a prefab name and not a prefab reference to avoid accidentally calling GameObject.Instantiate(). when I enable them in the scene. I have a realtime component setup that does connect to the server.
2 Replies
Hi @RonJames. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Short answer: scene objects with RealtimeView are valid, but they only get their models after the scene’s Realtime has registered them and the room is connected. If you enable them too early (or before RealtimeView registers), you’ll see “model is null.”
Checklist to fix:
- Ensure these are true “scene views” (placed in the scene, not instantiated at runtime). Scene views don’t use Realtime.Instantiate and will be initialized by Realtime after Start and upon connection. [RealtimeComponent; RealtimeView (Common Qs)]
- Don’t touch the model/ownership in Awake (or Start for scene views). For scene objects, wait until realtime.connected == true or subscribe to Realtime.didConnectToRoom before accessing RealtimeView/model. For component initialization, use OnRealtimeModelReplaced to react when the model is assigned. [RealtimeView (Common Qs); RealtimeComponent]
- If you’re enabling these objects after Start, make sure RealtimeView wasn’t disabled at Start (disabled scene RealtimeViews won’t register and won’t get a model). Don’t disable RealtimeView; instead, disable your own renderers/scripts and keep the RealtimeView enabled so it can register. [RealtimeView (Common Qs)]
- Verify the RealtimeView shows your RealtimeComponents in its Components list in the Inspector. If the prefab got corrupted (or child view relationships broke), the model won’t be created. [RealtimeComponents (Common Qs); RealtimeView page]
- For prefabs you do want to spawn at runtime, you must use Realtime.Instantiate("PrefabName", …) and keep the prefab in a Resources folder or use a custom load delegate (e.g., Addressables). Passing a prefab reference to Unity’s Instantiate will cause the exact error you’re seeing. [Realtime API; Realtime reference]
Practical pattern:
- In your scene RealtimeComponents, move model-dependent setup into OnRealtimeModelReplaced, and guard against null until it’s called.
- When enabling a hand-placed object after Start, ensure Realtime.connected is true, or delay enabling until didConnectToRoom fires. [RealtimeComponent; RealtimeView (Common Qs)]
If you follow the above and still get “model is null,” double-check:
- The RealtimeView wasn’t disabled at Start.
- The RealtimeView has the correct Realtime instance assigned (or left blank if there’s only one instance). [Advanced settings]
- The Components/Children lists in the RealtimeView inspector look correct (no missing component IDs/child views). [RealtimeView page]
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@378869779668140042> Kapa.ai is still learning and improving, please let me know how I did by reacting below.