# Using GetComponentByClass

**URL:** <https://forums.unrealengine.com/t/using-getcomponentbyclass/411844>\
**Category:** Community & Industry Discussion\
**Tags:** subclass, actorcomponent, tsubclassof, unreal-engine, Components, question\
**Created:** [December 9, 2017, 8:32pm UTC](https://forums.unrealengine.com/t/using-getcomponentbyclass/411844 "2017-12-09T20:32:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakoban](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jakoban](https://forums.unrealengine.com/u/Jakoban)\
**Post date:** [December 9, 2017, 8:32pm UTC](https://forums.unrealengine.com/t/using-getcomponentbyclass/411844/1 "2017-12-09T20:32:22Z")

</div>

Whenever I try to use GetComponentByClass I’m hit with some error like type name not allowed or something like that.Can someone just give me a clear example of using GetComponentByClass with UPrimitiveComponent? And what is supposed to mean----TSubclassOf ComponentClass?  
Thanks In Advance!

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [December 9, 2017, 9:26pm UTC](https://forums.unrealengine.com/t/using-getcomponentbyclass/411844/2 "2017-12-09T21:26:51Z")

</div>

`TSubclassOf` is same as `UClass*` it just limits the class section to specific base class relation. So `TSubclassOf<UActorComponent>` allows oyu to input only classes related to `UActorComponent`

You need to input `UClass*` and you can get `UClass*` of each `UObject` class by calling static function `StaticClass()` inside that class. So you should do something like this:

```
GetComponentByClass(UPrimitiveComponent::StaticClass());

```

---

<div class="post-metadata">

**Author:** ![Ebrahim.MR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebrahim.mr/32/1220185_2.png) [@Ebrahim.MR](https://forums.unrealengine.com/u/Ebrahim.MR)\
**Post date:** [February 4, 2019, 7:39am UTC](https://forums.unrealengine.com/t/using-getcomponentbyclass/411844/3 "2019-02-04T07:39:20Z")

</div>

Thank you for clarifying it. It helped me to understand it a lot.
