How to check if a BehaviorClass inherits a class

In my game, I have the class ITreeGenerator(which purely virtual class) and I will like to find all the classes that inherit that class. I did find a way to find all the classes that have been reflected in the BehaviorContext(getting the BehaviorClass of all class).
The end goal of this code is I am trying to create an object for all the classes that is registered to a ReflectContext that inherits ITreeGenerator

Hi @ravenboilinux, very interesting question!

Since you have ITreeGenerator and its derived classes hooked up to BehaviorContext, they should be registered with the RTTI system as well. In that case, you can use

AZ::IRttiHelper* derivedExternal = AZ::GetRttiHelper<DerivedExternal>();
// returns true if derived

To check each class. Let us know if that resolves your question.

1 Like

Can you use RttiHelper with a uuid? Since I don’t have type to use for AZ::GetRttiHelper(), since I am just have the uuid of the class and BehaviorClass that BehaviorContext has

Yes, if you have access to the SerializeContext then you could get the ClassData for ITreeGenerator and call CanConvertFromType to check each uuid:

AZ::SerializeContext::ClassData* iTreeGeneratorClassData = 
// returns true if derived
iTreeGeneratorClassData->CanConvertFromType(derivedUuid, serializeContext);

Or, you could access the ClassData for each potentially derived class, and get the IRttiHelper from there. Then you can use IsTypeOf method like so:

AZ::SerializeContext::ClassData* classData = 
AZ::IRttiHelper* derivedExternal = classData->m_azRtti;
// returns true if derived

Well does the ComponentApplicationBus::Events::GetSerializeContext return the SerializeContext when the game is running, or is it just a editor thing?

Yes, you should be able to use ComponentApplicationBus::Events::GetSerializeContext even while inside Game Mode.

1 Like

Thanks. I figure out a better way to find the Derived class is using the EnumerateDerived method on SerializeConext and using the IObjectFactor create to create the object. I found this while trying to figure out how should I create a custom motion event and how EmotionFX added motion events to the add new event menu.

1 Like

Nice, that’s a creative solution! Thanks for sharing it with us. :slight_smile:

1 Like