Realtime Model Persistence
Hello, I have a question regarding Realtime Model persistence. I want the model of a particular user to persist in the room whenever they leave and the room is still in session (other users in the room remain). Upon returning, I want the model to be reapplied to the Realtime Component. From reading documentation I think
RealtimeModel.destroyWhenOwnerLeaves = false
should make this possible. I'm setting this flag when the model is first initialized:
However, every time the owner of the model returns it always goes through the "fresh model" path so I think that means the model is created again instead of reapplying the persisted model. Am I understanding the persistence flags incorrectly or is there some built-in way to achieve what I'm trying to do?4 Replies
Hi @elg. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I can offer some insights into your question about Realtime Model persistence in NormalVR. However, it's important to note that the specific behavior you're describing isn't directly addressed in the provided documentation.
You're correct in your understanding that setting
destroyWhenOwnerLeaves = false
should prevent the model from being destroyed when the owner leaves the room. This is confirmed in the Server Authority + Ownership + Lifetime Flags documentation:
"Lifetime flags tell the server how long the state for a model should be retained. Models can be set to persist between sessions, or they can be automatically deleted when the owner or the last client leaves the room."
However, the behavior you're experiencing, where the model always goes through the "fresh model" path when the owner returns, isn't explicitly covered in the provided knowledge sources.
A few points to consider:
1. The isFreshModel
property is described in the RealtimeModel documentation as:
"True if this model was just locally created. This flag can be used to apply component settings or initial values to a newly instantiated model."
2. The isPersistent
property of RealtimeModel might be relevant here:
"If true, the object will persist after all clients leave the room."
3. The documentation also mentions that for persistent objects, you should set destroyWhenOwnerOrLastClientLeaves
to false when instantiating:
Source
Given this information, here are a few suggestions:
1. Make sure you're setting both destroyWhenOwnerLeaves
and destroyWhenLastClientLeaves
to false if you want the model to persist even when all clients leave.
2. Check if the isPersistent
property is set to true for your model.
3. Consider setting the persistence flags when instantiating the object, rather than in OnRealtimeModelReplaced
.
4. You might need to implement additional logic to check if a persisted model exists for a returning user and reapply it, rather than creating a fresh model each time.
However, the knowledge sources don't provide enough information to fully explain why you're always getting a fresh model or how to definitively solve this issue. It might be worth reaching out to NormalVR's support or community forums for more specific guidance on this behavior.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1346589764530475049> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
if the model is on the avatar it doesn't work, you have to realtime.instantiate it in the scene
@elg persistence works with scene views, but a fresh model is populated before you connect. Upon connection if a model that's persistent is already in the datastore, OnRealtimeModelReplaced is called to replace the model with the one that's in the room