Hi, I’m working on a project with vehicles. So, I’m working on 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.
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.
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)
//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?