| Home Page | Recent Changes | Preferences

# Destroying Objects

## Destroying Actors

Actors are destroyed by calling their Destroy() function. Destruction is latent, i.e. the actor is destroyed at the end of the current tick, although the Destroyed() event is executed immediately. The actor is moved to the list of destroyed actors then. Note that calling Destroy() will not halt the execution of a function that is already started, or stop other functions from being called on that actor. If you wish to avoid this behavior, the actor variable `bDeleteMe` is set to true when an actor has been "destroyed" but has not yet been deleted.

### Chain Of Events

When the Destroy() function is called, several other UnrealScript events get called as well before code execution continues after the call to Destroy().

1. the actor's EndState() event
2. the actor's Destroyed() event
3. the LostChild() event of the actor's Owner
4. all references to this actor are set to None
   Warning: This also detaches the actor from its children (i.e. sets their Owner property to None) without calling LostChild(). If the actor gains a new child afterwards, the engine gets confused and crashes the game soon.

## Destroying Non-Actor Objects

Objects will be cleaned up at garbage collection time, provided there are no Actors that retain references to them. You can explicitly force garbage collection using a console command, or wait for the normal collection during a level switch. See my notes on the new keyword about making sure your objects are safe for garbage collection.

## Related Topics

- UnrealScript
- Creating Actors And Objects
- Garbage Collection

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In