Google News
logo
Unity - Interview Questions
Difference between Destroy and DestroyImmediate unity function
In Unity, `Destroy()` and `DestroyImmediate()` are two functions used to remove a game object or a component from the scene.

The main difference between these two functions is the timing of when the object is destroyed.

`Destroy()` is used to remove an object or component at the end of the current frame. The object is marked for destruction and is removed from the scene during the next update cycle. The `Destroy()` function is generally preferred over `DestroyImmediate()` as it allows for better performance and memory management.

`DestroyImmediate()`, on the other hand, destroys an object or component immediately. This function bypasses the standard process of destroying objects and removes it from the scene immediately. This can cause issues with memory and performance, especially if you are calling the function frequently.
Advertisement