CreateDefaultSubobject() & NewObject() in Unreal Engine 5 C++

Written on: 2 February 2025


// Use in Constructor
UMyComponent* MyComp = CreateDefaultSubobject<UMyComponent>(TEXT("MyComponent"));


// Use during Runtime
UMyObject* MyObj = NewObject<UMyObject>(this);


TSubclassOf<UObject> MyDerivedClass;
UObject* MyDerivedObj = NewObject<UObject>(this, MyDerivedClass);