T . Kathiravan
2 min readApr 21, 2021

--

Destroying an Object in Unity

Destroy :
Destroy() is a function used to remove GameObjects , Components and Scripts at runtime.
Destroying an object is as important as that of Instantiating and modifying it.
Main reasons for destroying gameObjects include managing memory, getting rid of not-needed gameObjects .
Destroy method has 2 variants (Overload forms)
The first overload form simply Destroys the gameObject
Destroy(gameObject);

When I press Space key you can see the object is destroyed

Destroying GameObject

While, the second overload form, involves another parameter time, t as a float variable.
Destroy(gameObject,5.0f);
This will wait for the 5 seconds before destroying the gameObject.

We can destroy other objects too..

Destroy Components :

Component Destruction

We can also destroy script Instance

Destroying gameObjects is a very easy as it involves only one line of code, but the real magic happens when you call the method along with other statements to make the object’s destruction look and feel real and right.

--

--