Instance destroy

Explanation
This function destroys the instance from which the function is called. To destroy a different instance or collection of instances you must execute the function for these instances as is shown in the examples below.

Examples
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 ) but will produce a different instance id. instance_destroy only destroys the instance the function is called from, you cannot use instance_destroy to destroy one particular instance from another, in order to destroy one instance from another you have to use the command. For example, as follows:

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.

When you want to destroy a particular instance you need an id of it. For example you could use the following rather useless code to destroy an instance after you created it:

globalvar iii; iii = instance_create(100,100,obj_enemy01); with (iii) instance_destroy;

Of course you would normally destroy it at some other time than when you create it.