# Destroy(Object, float)

> Removes a GameObject, component, or asset.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static void Destroy(Object obj, float t)
```

### Parameters

**** (\[Object]\(/engine/6000.6/script-reference/unityengine/object)): The object to destroy.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The optional amount of time to delay before destroying the object.

### Remarks

Destroys the specified object. If a time delay (`t`) is specified, destruction occurs after t seconds have elapsed. The timer starts from the moment `Destroy` is called. Actual object destruction is always delayed until after the current Update loop, but always happens before rendering.

If the object is a component, only that component is removed and destroyed. If the object is a GameObject, the GameObject, all its components, and all its transform children are destroyed together.

Once `Destroy(obj, t)` is called, the object is scheduled for destruction after `t` seconds, regardless of whether the script component that called it is later disabled or destroyed.

`Destroy` is safe to call on objects that might already be destroyed or null. If the object is already destroyed before the scheduled time, no error is thrown when the timer expires. Unity’s internal system tracks the object's state and won't attempt to destroy it again.

The delay parameter `t` is affected by [Time.timeScale](/engine/6000.6/script-reference/unityengine/time/timescale.md). If [Time.timeScale](/engine/6000.6/script-reference/unityengine/time/timescale.md) is set to 0 (for example, if the game is paused), the destruction is delayed until time resumes.

Additional Resources: [Object.DestroyImmediate](/engine/6000.6/script-reference/unityengine/object/destroyimmediate.md)

```csharp
using UnityEngine;

public class ScriptExample : MonoBehaviour
{
    void DestroyGameObject()
    {
        Destroy(gameObject);
    }

    void DestroyScriptInstance()
    {
        // Removes this script instance from the game object
        Destroy(this);
    }

    void DestroyComponent()
    {
        // Removes the rigidbody from the game object
        Destroy(GetComponent<Rigidbody>());
    }

    void DestroyObjectDelayed()
    {
        // Kills the game object in 5 seconds after loading the object
        Destroy(gameObject, 5);
    }

    // When the user presses Ctrl, it will remove the
    // BoxCollider component from the game object
    void Update()
    {
        if (Input.GetButton("Fire1") && GetComponent<BoxCollider>())
        {
            Destroy(GetComponent<BoxCollider>());
        }
    }
}
```

Destroy is inherited from the UnityEngine.Object base class.
