MasterOX 水
MasterOX 水3w ago

realtime.destroy

how do you use realtime.destroy
2 Replies
kapa.ai
kapa.ai3w ago
Hi @MasterOX 水. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Realtime.Destroy() is a method provided by NormalVR's Realtime API to destroy a realtime prefab on all clients. This method must be used instead of the standard GameObject.Destroy() method in Unity. It can only be used with GameObjects that were instantiated with Realtime.Instantiate(). Here's how you can use it:
Realtime.Destroy(gameObject);
Realtime.Destroy(gameObject);
In this line of code, gameObject is the game object you want to destroy. It's important to note that if you're getting an error like "Server attempted to delete value from set for key that doesn’t exist in storage. This is a bug!", it generally happens when multiple clients attempt to delete the same model from a RealtimeSet at the same time. To prevent this, it's recommended to have the client that owns the object destroy it:
if (realtimeView.isOwnedLocally) Realtime.Destroy(gameObject);
if (realtimeView.isOwnedLocally) Realtime.Destroy(gameObject);
In this line of code, realtimeView.isOwnedLocally checks if the current client owns the object, and if it does, it destroys the object. You can find more information about this in the NormalVR documentation (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). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@758040514678489279> kapa.ai is still learning and improving, please let us know how it did by reacting below