# How to check child class of a virtual parent class?

**URL:** <https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153>\
**Category:** C++\
**Tags:** classes, child, owner, check, unreal-engine, question\
**Created:** [September 14, 2015, 2:43pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153 "2015-09-14T14:43:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e6436d8c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e6436d8c](https://forums.unrealengine.com/u/anonymous_user_e6436d8c)\
**Post date:** [September 14, 2015, 2:43pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153/1 "2015-09-14T14:43:29Z")

</div>

Hi, I’m working on a project with vehicles. So, I’m working on [WheeledVehicleMovementComponent.cpp](https://github.com/edsonsantoro/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Private/Vehicles/WheeledVehicleMovementComponent.cpp) class, and I want to check if the owner class of this component is my WheeledVehicleNW class, or maybe the child class of it, witch is my new class WheeledVehicleMovementComponentNW. Just a simple If statement would work, but I couldn’t understand it yet.

As far as I could understand, the classes are organized like this: APawn-\>WheeledVehicleNW-UWheeledVehicleMovementComponent-\>UWheeledVehicleMovementComponentNW.

---

<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:** [September 14, 2015, 3:09pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153/2 "2015-09-14T15:09:21Z")

</div>

This is how you check if object is related to class

```
SomeObject->IsA(USomeClass::StaticClass())

```

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [September 14, 2015, 3:53pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153/3 "2015-09-14T15:53:36Z")

</div>

At a higher level: Why do you want to make this check?  
In C++, and any language with polymorphism, it’s generally a code smell.  
Instead, you’ll typically want to use some polymorphic behavior – a virtual function that allows variation in behavior, or some component accessor that returns NULL or a component instance, depending on desired outcome.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e6436d8c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e6436d8c](https://forums.unrealengine.com/u/anonymous_user_e6436d8c)\
**Post date:** [September 14, 2015, 4:22pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153/4 "2015-09-14T16:22:16Z")

</div>

The WheeledVehicleMovementoComponent class is the base classes for both classes (the WheeledVehicleMovementComponent4W and my custom WheeledVehicleMovementComponentNW) . I have added a simple boolean inside it, under the Wheel Setup category (next to the wheel class, offset and bone name), but, I just want to show that boolean on UE4 interface if the child (object, component, class … I don’t know witch is right) that I have created is my custom movement component class… or it can check it’s parent, because it is different from the base one (wheeledvehicle)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e6436d8c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e6436d8c](https://forums.unrealengine.com/u/anonymous_user_e6436d8c)\
**Post date:** [September 14, 2015, 4:23pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153/5 "2015-09-14T16:23:06Z")

</div>

Can’t understand it, I’m too newbie to get it working …

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e6436d8c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e6436d8c](https://forums.unrealengine.com/u/anonymous_user_e6436d8c)\
**Post date:** [September 15, 2015, 3:17pm UTC](https://forums.unrealengine.com/t/how-to-check-child-class-of-a-virtual-parent-class/332153/6 "2015-09-15T15:17:01Z")

</div>

I’ve managed to get this working like so:

```
//Check our owner and set preferences
		AActor* ourOwner = UWheeledVehicleMovementComponent::GetOwner();
		if (ourOwner->GetClass()->IsChildOf(AWheeledVehicle::StaticClass())) {
			for (int32 WheelIdx = 0; WheelIdx < WheelSetups.Num(); ++WheelIdx)
			{
				
				WheelSetups[WheelIdx].bUsingDifferential = false;
			}
		}

```

Now, it sets the boolean to false only, even checking it on the interface. But, is there a way to make it a constant, read-only or maybe even not generate that bool when constructor is called?
