WorldThingSpawned
Jump to navigation
Jump to search
void WorldThingSpawned (WorldEvent e)
Usage
An event handler virtual function that is called when an actor spawns in the map.
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 spawned.
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
}