TSubclassOf
#include "Templates/SubclassOf.h" Description
A UClass wrapper that enforces a type constraint at edit time and in C++. Use it in UPROPERTYs to restrict what class the user can assign in the editor.
Caveats & Gotchas
- • A null TSubclassOf is valid and common — always null-check before using it to spawn or CDO-access.
- • Assigning a class that doesn't inherit from T at runtime will fail silently in shipping builds but assert in debug.
- • Works with Blueprint classes — if you assign a Blueprint subclass of T, TSubclassOf will hold its UClass.
Signature
template<typename T> class TSubclassOf Example
Spawn an actor of a configurable class C++
UPROPERTY(EditDefaultsOnly, Category="Spawning")
TSubclassOf<AActor> EnemyClass;
// In code:
if (EnemyClass)
{
GetWorld()->SpawnActor<AActor>(EnemyClass, SpawnTransform);
} Functions (1)
Utility 1 ▼
| Access | Type | Name |
|---|---|---|
| public | function | TSubclassOf::UE_REQUIRES (constrained conversion constructor) |
Properties
| Access | Type | Name |
|---|---|---|
| private | property | TSubclassOf::Class |
See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?