HaRrY
HaRrY5mo ago

Realtime.Destroy On owned realtime prefabs.

Can I destroy a RealtimePrefab by calling Realtime.Destroy even if someone else is an owner? Or do I have to take ownership first before destroying. I know it would destroy but I am thinking more like what will happen in the datastore?
3 Replies
kapa.ai
kapa.ai5mo ago
Hi @Harris Saleem. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In NormalVR, the recommended practice is to have the client that owns the object destroy it. This is to prevent issues that can occur when multiple clients attempt to delete the same model from a RealtimeSet at the same time. If multiple clients call Realtime.Destroy() on the same object at the same time, it can lead to errors. Here is the recommended way to destroy an object:
if (realtimeView.isOwnedLocally) Realtime.Destroy(gameObject);
if (realtimeView.isOwnedLocally) Realtime.Destroy(gameObject);
This code checks if the realtimeView is owned locally, and if it is, it calls Realtime.Destroy() on the gameObject. This ensures that only the owner of the object can destroy it, preventing potential conflicts. In terms of what happens in the datastore, if the destroyWhenOwnerLeaves or destroyWhenLastClientLeaves flags are set to true, the model will be destroyed when the owner of the model leaves the room or when the last client in the room leaves, respectively. If these flags are not set, the model will persist in the datastore even after the client disconnects. For more information, you can refer to the following documentation: - Destroy a prefab when a client disconnects (https://normcore.io/documentation/room/ownership-and-lifetime-flags#destroy-a-prefab-when-a-client-disconnects) - Common Questions (https://normcore.io/documentation/room/common-questions#im-getting-the-error-server-attempted-to-delete-value-from-set-for-key-that-doesnt-exist-in-storage-this-is-a-bug-how-do-i-fix-this) - RealtimeView Properties (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeView) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@250518782341021697> kapa.ai is still learning and improving, please let us know how it did by reacting below
maxweisel
maxweisel5mo ago
It will be destroyed and cleared from the datastore properly