instance_destroy()

Drag & Drop equivalent : GM026

 

Example, in an enemy instance; in a collision with a bullet:

 

instance_destroy();

 

This command destroys the instance that the command is in. You usually use this command in an enemy instance when you want it destroyed, perhaps when a bullet has hit it. The object isn't removed from the game program itself but the instance is destroyed. You can use the object again at any time (see instance_create) but will produce a different instance id.  instance_destroy() only destroys the instance it's in, you cannot use instance_destroy(<instance name>) to destroy one particular instance from another, in order to destroy one instance from another you have to use the with command:

 

with (obj_enemy01)

{

instance_destroy();

}

 

But be warned, ALL instances of the specified object will be destroyed, so if you had multiple instance of say, obj_enemy01, and you use the with command like the example above, all instances of obj_enemy01 will disappear because you're specifying an object name, of which there could be multiple copies running around. This could be useful though in, say, a puzzle game, where destroying a gem would destroy all of the same type.

 

Revision #2