Avatar

Noisy Kid Studios

Unleashing the UE Power

Need an UE developer? Contact Us

Pointer types in Unreal Engine

April 2, 2026

Memory management in Unreal Engine is a hybrid model that combines garbage collection for UObject types with smart pointers for standard C++ data. Understanding where each system applies is critical to avoid crashes, leaks, and invalid references.

At a high level, anything derived from UObject is managed by Unreal’s Garbage Collector. Everything else follows normal C++ lifetime rules, where you are responsible for ownership and destruction, typically through smart pointers.

Pointer types in Unreal Engine

You can divide pointer usage into two main categories: pointers for UObject types and pointers for non-UObject C++ data.

Pointers for UObject types managed by the Garbage Collector

TObjectPtr is the modern standard in Unreal Engine 5 for referencing UObjects inside class members. It replaces raw pointers in most cases. When used with UPROPERTY, it allows the Garbage Collector to track references correctly. In editor builds it provides additional safety and tracking, while in shipping builds it behaves like a raw pointer.

TWeakObjectPtr is used for non-owning references. It does not prevent the Garbage Collector from destroying the object. This makes it suitable for observer-style relationships where you do not want to control the lifetime of the object. Always check IsValid before accessing it.

TSoftObjectPtr is a soft reference that stores an asset path instead of a direct pointer. It allows you to defer loading until explicitly requested. This is essential for memory optimization when working with large assets such as textures, skeletal meshes, or levels.

TSubclassOf represents a class type rather than an instance. It is commonly used when you want to expose a configurable class in the editor, for example selecting which projectile class to spawn.

TSoftClassPtr is the soft reference equivalent of TSubclassOf. It allows you to reference classes without forcing them into memory until needed, which is useful when working with large Blueprint classes.

Important rule for UObject pointers

If you store a reference to a UObject inside a class, it must be visible to the Garbage Collector. This is typically done using UPROPERTY with TObjectPtr or other supported types. If the Garbage Collector cannot see the reference, it may destroy the object while you are still using it.

Example

UPROPERTY() 
TObjectPtr HealthComponent;


Without UPROPERTY, the reference is invisible to the Garbage Collector and unsafe.

Smart pointers for non-UObject C++ types

For plain C++ types that do not inherit from UObject, Unreal provides its own smart pointer implementations similar to the standard library.

TSharedPtr is a reference-counted pointer. The object is destroyed when the last shared pointer releases it. It is useful when multiple systems need shared ownership.

TSharedRef is similar to TSharedPtr but cannot be null. It guarantees that the object is always valid and is widely used in Slate APIs.

TWeakPtr is a weak reference to an object managed by TSharedPtr. It does not increase the reference count and is used to avoid circular ownership.

TUniquePtr represents exclusive ownership. Only one pointer owns the object, and it is destroyed automatically when the pointer goes out of scope. It is ideal for private data and clearly defined ownership.

Choosing the right pointer

If the object is a UObject that must stay alive, use UPROPERTY with TObjectPtr.

If the object is a UObject but you do not own it, use TWeakObjectPtr and validate before use.

If the object is a heavy asset that should not always be loaded, use TSoftObjectPtr or TSoftClassPtr and load it on demand.

If the object is a pure C++ type, use TSharedPtr when ownership is shared or TUniquePtr when ownership is exclusive.

Common mistakes

Using raw UObject pointers without UPROPERTY leads to invalid memory access when the Garbage Collector runs.

Holding strong references unintentionally can prevent objects from being collected, causing memory to grow over time.

Using TSharedPtr with UObject types is incorrect. UObject lifetime must always be handled by the Garbage Collector.

Forgetting to validate weak pointers can result in accessing destroyed objects.

Summary

Unreal’s memory model requires you to distinguish clearly between UObject and non-UObject types. Use Garbage Collector-aware pointers for UObject references and standard smart pointers for everything else. Correct usage ensures stability, prevents leaks, and keeps memory usage under control in both editor and runtime builds.

🔍