KneehighPark
KneehighPark2w ago

Calling Realtime.Destroy(GameObject gameObject)

When destroying a prefab/gameobject (that was instantiated through Realtime.Instantiate) using Realtime.Destroy, is MonoBehavior.OnDestroy() guaranteed to run?
4 Replies
kapa.ai
kapa.ai2w ago
Hi @KneehighPark. 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 provided knowledge sources, there is no explicit information about whether MonoBehaviour.OnDestroy() is guaranteed to run when calling Realtime.Destroy(GameObject gameObject). The documentation does not specifically address this aspect of the Realtime.Destroy() method. However, we can infer some relevant information from the available sources: 1. Realtime.Destroy() is the recommended method for destroying realtime prefabs on all clients, as mentioned in the Realtime API documentation: "Realtime.Destroy() must be used instead of GameObject.Destroy(). It can only be used with GameObjects that were instantiated with Realtime.Instantiate()." 2. The method is designed to synchronize the destruction of objects across all clients in the Normcore environment. 3. There's no specific mention of how Realtime.Destroy() interacts with Unity's standard MonoBehaviour lifecycle methods like OnDestroy(). Given this information, we cannot definitively state whether MonoBehaviour.OnDestroy() is guaranteed to run when using Realtime.Destroy(). To get a definitive answer, you would need to either test this behavior in your project or consult the Normcore support team for more detailed information about the internal workings of Realtime.Destroy(). As an expert in Unity, I can add that in standard Unity behavior, OnDestroy() is called when a GameObject is destroyed. However, since Realtime.Destroy() is a custom method for Normcore's networking system, its exact behavior regarding Unity's lifecycle methods is not clear from the provided documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@272987461100240896> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mechabit
Mechabit2w ago
yes
KneehighPark
KneehighParkOP2w ago
Thanks for confirming

Did you find this page helpful?