0% found this document useful (0 votes)
30 views

Unity - Scripting API - Object - Destroy

Unity Object Destroy

Uploaded by

Oke Gutz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Unity - Scripting API - Object - Destroy

Unity Object Destroy

Uploaded by

Oke Gutz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

30/8/2021 Unity - Scripting API: Object.

Destroy

unity.com

Search scripting...

MonoBehaviour
Motion Manual Object.Destroy
Scripting API
MovieTexture
Leave feedback
Network
Version: 2020.3 C#
SWITCH TO MANUAL
NetworkMessageInfo
NetworkPlayer
NetworkView Declaration
NetworkViewID public static void Destroy(Object obj,
float t = 0.0F);
Object
OcclusionArea
Parameters
OcclusionPortal
ParticleCollisionEvent obj The object to destroy.
ParticlePhysicsExtensions t The optional amount of time to delay
ParticleSystem before destroying the object.
ParticleSystemForceField
ParticleSystemRenderer Description
PatchExtents Removes a GameObject, component or asset.
PhysicMaterial
The object obj is destroyed immediately after the
Physics
current Update loop, or t seconds from now if a
Physics2D time is specified.
If obj is a Component, this
PhysicsJobOptions2D method removes the component from the
PhysicsMaterial2D GameObject and destroys it.
If obj is a
GameObject, it destroys the GameObject, all its
PhysicsScene
components and all transform children of the
PhysicsScene2D GameObject.
Actual object destruction is always
PhysicsSceneExtensions delayed until after the current Update loop, but is
always done before rendering.

Note: When destroying MonoBehaviour scripts,


OnDisable and OnDestroy are called before the
script is removed.

using UnityEngine;

public class ScriptExample : MonoBeh


{

void DestroyGameObject()

Destroy(gameObject);

https://docs.unity3d.com/ScriptReference/Object.Destroy.html 1/3
30/8/2021 Unity - Scripting API: Object.Destroy

unity.com
void DestroyScriptInstance()

Search scripting... {

// Removes this script insta


MonoBehaviour Destroy(this);

Motion Manual Scripting


}
API
MovieTexture
void DestroyComponent()

Network
Version: 2020.3 C#
{

NetworkMessageInfo
// Removes the rigidbody fro
NetworkPlayer Destroy(GetComponent<Rigidbo
NetworkView }

NetworkViewID
void DestroyObjectDelayed()

Object
{

OcclusionArea // Kills the game object in


OcclusionPortal Destroy(gameObject, 5);

ParticleCollisionEvent }

ParticlePhysicsExtensions
// When the user presses Ctrl, i
ParticleSystem // BoxCollider component from th
ParticleSystemForceField void Update()

ParticleSystemRenderer {

if (Input.GetButton("Fire1")
PatchExtents
{

PhysicMaterial Destroy(GetComponent<Box
Physics }

Physics2D }

PhysicsJobOptions2D
PhysicsMaterial2D
PhysicsScene
PhysicsScene2D Destroy is inherited from the UnityEngine.Object
PhysicsSceneExtensions base class.

Did you find this page useful? Please give it


a rating:

Report a problem on this page

https://docs.unity3d.com/ScriptReference/Object.Destroy.html 2/3
30/8/2021 Unity - Scripting API: Object.Destroy

Is something described here not working as you expect it to? It


unity.com
might be a Known Issue. Please check with the Issue Tracker
Search scripting...
at issuetracker.unity3d.com .
MonoBehaviour
Motion Manual Scripting API
MovieTexture Copyright ©2021 Unity Technologies. Publication Date:

Network
Version: 2020.3 C#
2021-08-23.
NetworkMessageInfo
NetworkPlayer Tutorials
Community Answers
Knowledge

NetworkView
Base
Forums
Asset Store
NetworkViewID
Object
OcclusionArea
OcclusionPortal
ParticleCollisionEvent
ParticlePhysicsExtensions
ParticleSystem
ParticleSystemForceField
ParticleSystemRenderer
PatchExtents
PhysicMaterial
Physics
Physics2D
PhysicsJobOptions2D
PhysicsMaterial2D
PhysicsScene
PhysicsScene2D
PhysicsSceneExtensions

https://docs.unity3d.com/ScriptReference/Object.Destroy.html 3/3

You might also like