How do I reset all values of models in a room?
I just added a new ability to switch rooms by hitting a button, but some of the models don't refresh and I keep variables like destroyed assets in a new room. How do I make sure that opening a new room will act as though I'm entering a fresh one?
5 Replies
Hi @Alix Ollivier. 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 entering a new room in Normcore acts as though you're entering a fresh one—with all models reset and no lingering variables or destroyed assets—you need to make sure that:
1. You are actually connecting to a new room: When you call
- Use a unique room name for each new session to guarantee a fresh datastore. - Set lifetime flags so models are destroyed when the last client leaves. - Clean up any local-only state when switching rooms. If you follow these steps and still see old state, double-check your prefab and model settings for persistence flags. If you need to programmatically clear models, you may need to remove them from the datastore before leaving the room, but the knowledge sources do not provide a direct API for "resetting" all models at once. If you need more granular control, consider destroying and recreating the relevant models or prefabs when switching rooms. If you have further issues, please provide more details about how you are switching rooms and managing your models. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Realtime.Connect()
with a new room name, Normcore will connect to a different room server, and the datastore should be fresh for that room. If you reuse the same room name, persistent models (those not set to be destroyed when the last client leaves) will remain, and you may see old state carried over Room.
2. Model Lifetime Flags: If your models or prefabs are set to persist between sessions (i.e., their "Destroy When Owner Or Last Client Leaves" flag is unchecked or destroyWhenOwnerOrLastClientLeaves: false
), their state will be saved and restored when re-entering the same room. To ensure a fresh state, make sure this flag is set to true
for models that should not persist Ownership + Lifetime Flags.
3. Scene Reinitialization: When switching rooms, ensure you clean up any local state or scene objects that are not managed by Normcore, as these will not be automatically reset by joining a new room.
4. Persistent Models: If you have models marked as persistent, they will be serialized to disk and restored when the room is rejoined. To avoid this, do not mark models as persistent unless you want their state to carry over between sessions Datastore Persistence.
Summary:- Use a unique room name for each new session to guarantee a fresh datastore. - Set lifetime flags so models are destroyed when the last client leaves. - Clean up any local-only state when switching rooms. If you follow these steps and still see old state, double-check your prefab and model settings for persistence flags. If you need to programmatically clear models, you may need to remove them from the datastore before leaving the room, but the knowledge sources do not provide a direct API for "resetting" all models at once. If you need more granular control, consider destroying and recreating the relevant models or prefabs when switching rooms. If you have further issues, please provide more details about how you are switching rooms and managing your models. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@185325614775926784> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
If you enter a fresh room all values will be reset
If you're not seeing that, it sounds like there is a bug here, but Normcore replaces the models on all objects with new instances when you start connecting
destroyed assets like objects in the scene? have you tried reloading the scene as well?
you shouldn’t need to do that