# Cannot get GetComponents to work with TSubclassOf

**URL:** <https://forums.unrealengine.com/t/cannot-get-getcomponents-to-work-with-tsubclassof/405149>\
**Category:** Community & Industry Discussion\
**Tags:** tsubclassof, unreal-engine, Components, question\
**Created:** [September 21, 2017, 5:50pm UTC](https://forums.unrealengine.com/t/cannot-get-getcomponents-to-work-with-tsubclassof/405149 "2017-09-21T17:50:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_07ba773b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_07ba773b](https://forums.unrealengine.com/u/anonymous_user_07ba773b)\
**Post date:** [September 21, 2017, 5:50pm UTC](https://forums.unrealengine.com/t/cannot-get-getcomponents-to-work-with-tsubclassof/405149/1 "2017-09-21T17:50:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Semitable](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Semitable](https://forums.unrealengine.com/u/Semitable)\
**Post date:** [September 21, 2017, 11:56pm UTC](https://forums.unrealengine.com/t/cannot-get-getcomponents-to-work-with-tsubclassof/405149/2 "2017-09-21T23:56:56Z")

</div>

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](https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1357727-how-to-use-getcomponents-with-tsubclassof)
