Calling CreateDefaultSubobject crashes editor!

CreateDefaultSubobject can’t be used outside of the class constructor. As the name suggests, it’s for creating a default sub-object.

To create actor components at runtime you must use NewObject, then manually register it. Do NOT give the component a name, use the default NAME_None parameter.



UMyComponent* NewComp = NewObject<UMyComponent>(Actor, ComponentClass);
check(NewComp);

NewComp->RegisterComponent();


6 Likes