Description
Removes an actor from the world, calling Destroyed() and cleaning up all associated resources. Returns true if the actor was destroyed or was already pending destruction.
Caveats & Gotchas
- • In game code, prefer calling AActor::Destroy() on the actor directly — it calls this function internally and is more idiomatic.
- • Never use the actor pointer after DestroyActor — the object enters a pending-kill state immediately. Null out any stored references and check IsValid() on others.
- • In networked games, only the server should destroy replicated actors. Client calls on server-owned actors have no effect.
Signature
bool DestroyActor( AActor* Actor, bool bNetForce=false, bool bShouldModifyLevel=true ) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Actor | AActor* | The actor to destroy. | — |
| bNetForce | bool | Forces destruction in networked contexts where it would otherwise be deferred. Leave false in game code. | false |
| bShouldModifyLevel | bool | If true, marks the level package dirty. Set false in editor bulk operations. | true |
Return Type
bool Example
Destroy an actor from game code C++
// Preferred: call Destroy() on the actor itself
MyActor->Destroy();
MyActor = nullptr;
// Direct world call (less common, e.g. from a manager class)
GetWorld()->DestroyActor(SomeActor); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?