Skip to main content

Resource

Smart Pointers & References

Compare Unreal Engine pointer and reference types by ownership, garbage collection support, and intended use.

Start here

The essentials

The deciding question is almost always the same: is the target a UObject? These eight cards cover the rest. The reference below lists each type's declaration and when to reach for it.

01

UObject or plain type

The first question is whether the target is a UObject. Actors, components, and UObject-derived classes are managed by the garbage collector and need UObject-aware pointers. Plain C++ structs and classes use the standard smart pointers.

02

UPROPERTY

A UObject pointer marked UPROPERTY is a strong reference, so the garbage collector keeps the object alive. Without UPROPERTY, the object can be collected while a raw pointer still points at it.

03

TObjectPtr

Use TObjectPtr for UPROPERTY members in headers. It compiles to a raw pointer in shipping builds and adds access tracking and lazy loading in the editor.

04

TWeakObjectPtr

TWeakObjectPtr references a UObject without keeping it alive, and becomes null when the object is destroyed. Check IsValid() before using it. It's ideal for timers, callbacks, and back-references.

05

TSoftObjectPtr

TSoftObjectPtr stores an asset's path rather than the asset itself, so the reference uses no memory until the asset loads. Load it on demand with LoadSynchronous or async streaming.

06

Non-UObject pointers

For plain C++ types: TSharedPtr and TSharedRef share reference-counted ownership, TUniquePtr owns alone and moves instead of copying, and TWeakPtr observes without owning. These map to std::shared_ptr, unique_ptr, and weak_ptr; like std::shared_ptr, TSharedPtr defaults to thread-safe atomic reference counting, with ESPMode::NotThreadSafe as a faster single-threaded option.

07

Non-null types

TSharedRef and TNonNullSubclassOf cannot hold null. Use them when null is always a bug: TSharedRef won't compile against null, and TNonNullSubclassOf asserts if assigned null.

08

UObject containers

A UPROPERTY TArray, TMap, or TSet of UObject pointers keeps every element alive. Without UPROPERTY, the garbage collector can clear the elements.

Pointer types

Unreal Directive is free and ad-free.

If it saved you time, you can help keep it that way.

Donate