How to Dynamically Instantiate Actor Components?

Well, I’m back at this old song and dance again with actor components. I don’t understand how you would use them in OOP. Each actor component seems to have its own special constructor method that has to be called from an Actor and its strikes me as being super weird why you can’t have a class variable of a base actor component class that can be dynamically and then instantiate whatever that component is. This is hard-coded object instantiation at its weirdest.

In my case here, I have a common actor component class defined in C++ called Buff Component which is used virtually to create other buff components. In blueprint, I have an actor called Pickup Distributor which creates these buff components on actor overlap for the overlapping actor. Pickup Distributor blueprint has a variable of Buff Component which can be defined to be any buff component type according to the Pickup Distributor’s instance. But because of the current nature of Add Component, I seem to be stuck at a design pattern issue where I’d have to hard-code every possible buff component type that could be spawned.

So I ask again, am I even using Actor Components correctly? It seems like every time I try to use them for something creative, I find using normal Actors FAR less frustrating.

First time I encountered this issue

Other posts similar to my issue

I’m trying to come up with a C++ wrapper method to do what I want cause it seems there no way to create an actor component in blueprint based on a class template.

I’m having issues though. I may not have done this right because its throwing compile errors. Finding example on this using actor components is hard. Plenty on scene components but not actor components.

UActorComponent* UApolloLibrary::ConstructActorComponent(UClass *actorComponent, AActor *owner)
{
	return owner->CreateDefaultSubobject<actorComponent>(owner, TEXT("CustomComponent"), false);
}


error C2672: 'UObject::CreateDefaultSubobject': no matching overloaded function found
error C2974: 'UObject::CreateDefaultSubobject': invalid template argument for 'TReturnType', type expected

Is there some kind of prototype design pattern I can use here?