Cannot get GetComponents to work with TSubclassOf

I have a base class for a component called UBrushDynamicComponent, and various component classes that derive from it.

On my actor class, I want to be able to have an array I can iterate over which contains all of the components on the actor that derive from that class.

In my header file I have the following array set up:

TArray<TSubclassOf<UBrushDynamicComponent>> BrushDynamicsArray;

I want to populate this array with all the attached components that are a subclass of UBrushDynamicComponent. What I’m trying is something like this:

GetComponents<TSubclassOf<UBrushDynamicComponent>>(BrushDynamicsArray);

But it doesn’t work. I’ve been trying loads of things based on the error it throws when trying to build, but I can’t figure it out.

How can I end up with an array of all the components on my actor that derive from a particular class?

TArray<UDynamicBrushComponent*> DynamicsArray;
GetComponents(BrushDynamicsArray);
This did the trick. TSubclassOf is not needed, since a subclass is also the original class.

Also, you have to call the function after the components have been initialized (for example in begin play)

More here: How to use GetComponents with TSubclassOf? - C++ Programming - Unreal Engine Forums