UObject Equivalent of AActor::IsChildOf()?

My question is very straightforward, is there any possible method of determining whether two classes which are derived from UObject (NOT AActor) are related in C++, ie. if one is the child of another. I know that actors have the simple AActor::IsChildOf function, however I’m unable to find such an equivalent for UObjects. I’ve seen the blueprint solution:

but I’d like to know if there’s a more elegant solution than digging around in the engine files to expose the Kismet math library to my project and jerry-rig some function calls.

The reason I ask this is because I’m setting up an inventory system and need to know how to create references to items-- should they be a basic UItem, or perhaps UArmor or UWeapon?

Thank you in advance!

Hey Bolt-Action,

First of all you should be able to check it simply by casting, for example:

AActor * a = AActor();
if(Cast<UObject>( a )) // the cast returns nullptr when failed
{
 // AActor can be casted into UObject therefor AActor is child of UObject
}

But if you want to check if a class is child of another class (like the BP node you posted) You can do this:

AActor* a;
a->GetClass()->IsChildOf<UObject>(); // returns true if class is child of other class
// or
UClass * actorClass = AActor::StaticClass();
actorClass->IsChildOf<UObject>();

Hope this helps :slight_smile:
Elias

Thanks, that’s exactly what I’m looking for!