Model stays on datastore after destroying object view
This happens changing scenes (keeping realtime over scenes), in repeated scenes we found that the model used is not restored after destroy, so on OnRealtimeModelReplaced() the model comes with the values of the last scene
12 Replies
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:
----------------------
The behavior you're describing—where a model remains in the datastore after destroying its associated object, and its values persist across scene changes—relates to how Normcore handles model persistence and object destruction.
Key points from the documentation:
- Destroying Objects: When you destroy a realtime object, you must use
The model persists because it is either not being destroyed correctly or is marked as persistent. Double-check your destruction logic and lifetime flags to ensure the desired behavior Ownership + Lifetime Flags, RealtimeView Advanced Settings, Datastore Persistence. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Realtime.Destroy()
rather than Unity's standard Destroy()
method. This ensures the object is properly removed from the datastore on all clients. If you use the wrong destroy method, the model may remain in the datastore and persist its state across sessions or scene reloads Realtime class reference.
- Persistence and Lifetime Flags: If your model or RealtimeView is marked as persistent (i.e., "Destroy When Owner Or Last Client Leaves" is unchecked), the model will remain in the datastore even after all clients leave or the object is destroyed. This is by design, to allow for persistent collaborative spaces or objects Ownership + Lifetime Flags, Datastore Persistence.
- Scene Changes: If you keep the Realtime instance alive across scenes and re-instantiate objects with the same identifiers or scene UUIDs, Normcore will restore the model from the datastore, including any persistent values from the previous session or scene. This is expected if the model was not destroyed or if it is marked as persistent RealtimeView Advanced Settings.
Why does the model come with old values in OnRealtimeModelReplaced()?
- If the model was not properly destroyed (e.g., not using Realtime.Destroy()
), or if the object/model is set to persist, the datastore will retain its last state. When you re-instantiate the object (with the same RealtimeView/UUID), Normcore will provide the existing model from the datastore, not a fresh one.
How to resolve:
- Ensure you are using Realtime.Destroy()
to remove objects you want fully deleted from the datastore.
- If you do not want the model to persist, make sure the "Destroy When Owner Or Last Client Leaves" flag is enabled for the RealtimeView or set the appropriate lifetime flag when instantiating the prefab.
- If you want a fresh model each time, ensure the object is not marked as persistent and is properly destroyed before leaving the scene.
Summary:The model persists because it is either not being destroyed correctly or is marked as persistent. Double-check your destruction logic and lifetime flags to ensure the desired behavior Ownership + Lifetime Flags, RealtimeView Advanced Settings, Datastore Persistence. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@391444583034257420> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
are you talking about a scene view or a prefab view?
scene view
this is normal behaviour then cos you can't destroy a scene view, try a prefab view instead
So I should call Realtime.Instantiate each time I load a same scene? If that is the approach, is it ok to let the objects to be destroy by the scene changing? or I have to use Realtime.Destroy before the scene changing?
if you're persisting the scene realtime then probably not
depending on the lifetime flags
I have sperate avatar and scene realtimes so when I change scenes it disconnects from the scene realtime
my avatar realtime is persistent and my scene realtime is not
You mean the gamobject the realtime component is attached on? I keep it over scenes with DontDestroyOnLoad, with that in mind, it would be enough to change scenes without calling Realtime.Destroy for each prefab I want to be restored in datastore?
I don't think so, unity.destroy doesn't destroy the model
I see, if I want to destroy the model also in that moment, I should use Realtime.Destroy, anyway I guess the lifetime flags can handle it at the end of the session, right?
when you leave the room yes
alright, I understand more of it now, thanks 🙂