jos_valentin
jos_valentin2w ago

How to know when scene object views are fully initialized

Want to know when is it sure that all the views and models of an object are initialized and connected to the room
10 Replies
kapa.ai
kapa.ai2w ago
Hi @jos_valentin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To ensure that all RealtimeViews and their models for scene objects are fully initialized and connected to the room, you should wait until the Realtime instance is connected. This is indicated by either: - The Realtime component’s didConnectToRoom event firing, or - The Realtime.connected property being true For scene objects (not prefabs), initialization of views and models happens after the connection to the room is established. Accessing ownership or model data before this point can result in errors such as “This view doesn't have a model yet. Wait until the model is present before interacting with the ownership.” Therefore, you should place any logic that depends on fully initialized views and models inside the didConnectToRoom event handler or after checking that Realtime.connected is true. Example usage:
void Awake() {
_realtime = GetComponent<Realtime>();
_realtime.didConnectToRoom += OnDidConnectToRoom;
}

void OnDidConnectToRoom(Realtime realtime) {
// All scene RealtimeViews and models are now initialized and connected
// Safe to interact with ownership, models, etc.
}
void Awake() {
_realtime = GetComponent<Realtime>();
_realtime.didConnectToRoom += OnDidConnectToRoom;
}

void OnDidConnectToRoom(Realtime realtime) {
// All scene RealtimeViews and models are now initialized and connected
// Safe to interact with ownership, models, etc.
}
If you’re dealing with prefabs instantiated via Realtime.Instantiate(), their views and models are ready by the time Start() is called on any script on the prefab. For scene objects, always wait for the connection event as described above Realtime Common Questions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@391444583034257420> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
jos_valentin
jos_valentinOP2w ago
But there is an important thing here, I have my Realtime component persistent through scenes that have realtime views objects, on each time those scenes are loaded i want to know when all of those models are initialized and connected, so OnDidConnectToRoom is not enough in this case @kapa.ai I have my Realtime component persistent through scenes that have realtime views objects, on each time those scenes are loaded i want to know when all of those models are initialized and connected, so OnDidConnectToRoom is not enough in this case
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I'm sorry, but the knowledge sources do not explicitly describe a built-in event or callback that fires specifically when all RealtimeViews and their models in a newly loaded scene (with a persistent Realtime component) are fully initialized and connected. The documentation states that for scene objects, you should wait for the Realtime.didConnectToRoom event or check Realtime.connected, but it does not address the scenario where the Realtime instance persists across multiple scene loads and new RealtimeViews are registered after the initial connection Realtime Common Questions. If you need to know when all RealtimeViews in a newly loaded scene are initialized, you may need to implement your own tracking system. For example, you could have each RealtimeView or a custom manager script signal when its OnRealtimeModelReplaced() method is called, and then aggregate these signals to determine when all expected views are ready. However, this approach is not described in the official documentation. If you require more precise or built-in support for this workflow, I recommend reaching out to the Normcore community or support channels for guidance, as the current documentation does not provide a direct solution for this use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@391444583034257420> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mechabit
Mechabit2w ago
onmodelreplaced is the method you should use although on did connect to room should work as well. what errors are you getting?
jos_valentin
jos_valentinOP2w ago
No errors, I have my Realtime component in a starting scene which works as matchmaking waiting for players to connect to the room, there the didConnectToRoom event is fired correctly, then we load scene levels that have scene objects with realtimeviews, in those cases the objects exists since Start() but is not sure that the models are ready for modifiyng from there. As far as I know, OnRealtimeModelReplaced can't tell me when the model is connected to the room, might the flag model.isRoomConnected could be the solution?
Mechabit
Mechabit2w ago
it'd be easier if you have a separate realtime component in the scene with the scene views in it and then connect run the Connect() function on the 2nd Realtime after the scene loads it's how I and normal do it 1 realtime for avatars and session based communication and a 2nd realtime for scene views for games with multiple scenes the 2 realtimes need different room names like group1avatars and group1scene1
jos_valentin
jos_valentinOP7d ago
I see, so It would be a Realtime component per level scene, I'll try that approach, thanks 🙂 A question about that idea, The 1st realtime would be persistent through scenes while the 2nd ones per levels scenes will live only on those scenes, am I correct?
Mechabit
Mechabit7d ago
Yep, also avatars need to have don't destroy on load as well This method keeps scene view data from persisting past the scene

Did you find this page helpful?