WorldThingDestroyed
Jump to navigation
Jump to search
void WorldThingDestroyed (WorldEvent e)
Usage
An event handler virtual function that is called when an actor is destroyed.
Note: "destroyed" doesn't mean killed. Reducing an actor's health to 0 kills it, but an actor can only be destroyed if it's completely removed from the game. Most actors don't disappear when killed, and those that do (such as Doom's Lost Souls), only do it when their animation ends, not as soon as their health is reduced to 0.
Passed values
This event gets a pointer to the WorldEvent struct and can read the following from it by preceding the value with e.
:
- Actor thing
e.thing
is a pointer to the actor that was destroyed.
Examples
This event handler puts all projectiles in an array (which is globally accessible by finding the event handler with EventHandler.Find()), and removes them when they're destroyed:
class MyEventHandler : EventHandler
{
array<Actor> allProjectiles;
override void WorldThingSpawned(WorldEvent e)
{
// if the actor has the MISSILE flag, put it in the array:
if (e.thing.bMissile)
{
allProjectiles.Push(e.thing);
}
}
override void WorldThingDestroyed(WorldEvent e)
{
// when an actor is destroyed, check if it was in the array,
// and if so, remove it from it:
int index = allProjectiles.Find(e.thing);
if (index < allProjectiles.Size())
{
allProjectiles.Delete(index);
}
}
}
// Example of reading it from elsewhere in the code:
let handler = MyEventHandler(EventHandler.Find('MyEventHandler'));
if (handler)
{
// do something with handler.allProjectiles here
}