Hi guys,
I want my player character to have a function that takes a TSubclassOf variable.
This function should create a component of the exact class the TSubclassOf variable is, but I cant figure out a way to do this.
My question is:
Is it possible to create a component based on the class of a TSubclassOf variable and if yes how?
Thanks
You mean UClass* (TSubclassOf is just UClass* template that limits class selection in editor to specific relation)
UClass* MyClass = UMyAwesomeComponent::StaticClass();
UActorComponent* NewComp = NewObject<UActorComponent>(this, MyClass);
NewComp->RegisterComponent();
RegisterComponent takes outer Actor that you specified in NewObject in first argument, so if we inside Actor we simply use “this”
Oh man it’s so simple, I should have come up with this earlier.
But thanks that’s exactly what I needed.
yup awesome just what i needed as well.