RealDocs

UObject::MarkAsGarbage

function CoreUObject Since 5.0
#include "UObject/Object.h"
Access: public

Description

Marks this UObject to be destroyed by the garbage collector on the next GC pass. After calling this, `IsValid()` returns false. Use this instead of `delete` to destroy UObjects.

Signature

void MarkAsGarbage()

Return Type

void

Caveats & Gotchas

  • Previously named `MarkPendingKill()` which was deprecated in UE 5.0.
  • The object is not immediately destroyed — it persists until the GC runs.
  • AActor subclasses should prefer `Destroy()` which also handles actor lifecycle cleanup.

Example

Disposing a UObject C++
UMyObject* Obj = NewObject<UMyObject>(this);
// ... use Obj ...
Obj->MarkAsGarbage(); // Schedule for GC
// IsValid(Obj) now returns false

Version History

Introduced in: 5.0

Version Status Notes
5.6 stable
5.0 stable Replaces deprecated MarkPendingKill().

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.