How to properly shutdown and disconnect a normcore app?
We notice that when we disconnect from a room, we can still get calls to OnRealtimeModelReplaced on one or two components. What is the best practise for shutting down our app and disconnecting from Normcore?
3 Replies
Hi @DC. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To properly shut down and disconnect a Normcore app, the recommended approach is to call the appropriate disconnect method on your Realtime instance. For most use cases, you should use the Realtime API directly and avoid interacting with the Room or Datastore APIs yourself. Specifically, you should call
realtime.Disconnect()
to disconnect from the room, rather than calling room.Disconnect()
or manipulating the datastore directly. This ensures that all cleanup and event handling is managed correctly by Normcore’s systems, including the teardown of RealtimeViews and their models Datastore.
Regarding your observation that OnRealtimeModelReplaced
is still called on some components after disconnecting: this can happen because, during the disconnect process, Normcore may replace or clear models as part of its cleanup routine. This is expected behavior, as the system ensures that all models are properly disposed of and that components are notified of these changes.
Best practices for shutdown:
- Always use realtime.Disconnect()
to disconnect from a room.
- If you have event handlers or logic in OnRealtimeModelReplaced
, ensure they can handle the case where the model is being set to null
or replaced as part of the disconnect process.
- Avoid direct calls to lower-level APIs like room.Disconnect()
or direct datastore manipulation, as this can bypass important cleanup logic Datastore.
If you need to perform additional cleanup, you can listen for the didDisconnectFromRoom
event on your Realtime instance to trigger your own shutdown logic after Normcore has finished disconnecting.
If you continue to see unexpected behavior, it may be worth reaching out to the Normcore community or support for further assistance, as some edge cases may require more specific handling.
References:
- Datastore
- Realtime API
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1259730396577529917> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
This is intentional, RealtimeViews and their components in the scene are given fresh models on disconnect as they need models before connecting to a new room