Destroys the calling instance, removing it from the room.



Returns: N/A


You call this event whenever you wish to "destroy" an instance which will remove it from the room, but you should note a couple of things about this however.

First, when you destroy an instance, its destroy event is called immediately after the code or action that calls the destroy. Second, although the destroy event is performed, the instance is not immediately removed from the game, as it will continue to perform the code contained in the current event and only when the current event is over will it be removed from the game.

So, if you have, for example, this code:

if hp <=0 instance_destroy();
score += 10;

The variable "score" will be incremented even though the instance_destroy function has been called, and the instance will finally be removed from your game at the end of the event. Be careful of this, as if you have (for example) created a dynamic resource for the instance, like a data structure, then destroyed that resource in the destroy event, if there are any references to it after the destroy function or action has been performed then you will get an "unknown resource" error, as the destroy event removed it from the game.


with (obj_Enemy)

The above code will destroy all active instances of "obj_Enemy".

Back: Instance Functions
Next: instance_exists
© Copyright YoYo Games Ltd. 2015 All Rights Reserved