In GameMaker, destroying an instance removes it from the room and frees up the memory that was allocated for it. To destroy an instance, you can use the
instance_destroy() function within an instance's code block.
Here is an example of how to use
If you want to destroy another specific instance, you must reference that instance by its ID:
You can also destroy an instance from within a collision event or any other event by simply calling
instance_destroy() without referencing a specific instance ID, which defaults to destroying the calling instance itself.
It's important to note that when an instance is destroyed, it will not run any more code in the step in which it was destroyed. However,
Destroy event code will still be executed, allowing you to perform clean-up tasks such as saving information or creating particles.
instance_destroy(), here are some best practices:
instance_destroy(). Accessing a destroyed instance will result in an error.
Destroy event of the object to handle any necessary clean-up actions for the instance.
The above examples are valid in both GameMaker Studio 1.4 and GameMaker Studio 2.