Resource
Compare Unreal Engine pointer and reference types by ownership, garbage collection support, and intended use.
Start here
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.
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.
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.
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.
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.
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.
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.
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.
A UPROPERTY TArray, TMap, or TSet of UObject pointers keeps every element alive. Without UPROPERTY, the garbage collector can clear the elements.
Pointer types
Non-owning references for safe observation. They never extend their target's lifetime, and access returns null once it's gone.
Exclusive ownership for non-UObject types. One owner, moved rather than copied.
Path-based references that don't load their target until you ask. The basis for on-demand asset loading.
Direct UObject references and class wrappers. Strong only while held by a UPROPERTY or an explicit guard.
Collections that act as strong references to their UObject elements when declared as a UPROPERTY.
Related Content
Unreal Directive is free and ad-free.
If it saved you time, you can help keep it that way.