# Casting from a parent class to a TSubclassOf

**URL:** <https://forums.unrealengine.com/t/casting-from-a-parent-class-to-a-tsubclassof/503067>\
**Category:** C++\
**Tags:** unreal-engine, question, UE4-27\
**Created:** [March 1, 2022, 11:48am UTC](https://forums.unrealengine.com/t/casting-from-a-parent-class-to-a-tsubclassof/503067 "2022-03-01T11:48:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![HAF-Blade](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/haf-blade/32/88718_2.png) [@HAF-Blade](https://forums.unrealengine.com/u/HAF-Blade)\
**Post date:** [March 1, 2022, 1:10pm UTC](https://forums.unrealengine.com/t/casting-from-a-parent-class-to-a-tsubclassof/503067/2 "2022-03-01T13:10:25Z")

</div>

Tried this?

> [@Best way to check class type in C++](https://forums.unrealengine.com/t/best-way-to-check-class-type-in-c/396569):
>
> Lets take a look at the below snippet of code: //Check if there's a valid object to grab if (actorHit != NULL) { //Retain a reference to the owning character and the grabbed item. myOwningCharacter = Cast\<ABaseCharacter\>(actorThatIsGrabbing); myGrabbedItem = Cast\<ABaseItem\>(actorHit); if(Cast\<ABaseWeapon\>(myGrabbedItem) != NULL) { this-\>GrabWeapon(myGrabbedItem); } else { this-\>GrabItem(myGrabbedItem); } } As you can see, we are checking to see if myGrabbedItem is …

---

_[View the full topic](https://forums.unrealengine.com/t/casting-from-a-parent-class-to-a-tsubclassof/503067)._
