How to check if a BehaviorClass inherits a class

0

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

asked 3 years ago182 views
7 Answers
0
Accepted Answer

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

answered 3 years ago
0

Hi @REDACTEDUSER

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
derivedExternal->IsTypeOf(AZ::AzTypeInfo<ITreeGenerator>::Uuid());

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

answered 3 years ago
0

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

answered 3 years ago
0

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 = 
    serializeContext->FindClassData(iTreeGeneratorUuid);
// 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 = 
    serializeContext->FindClassData(uuid);
AZ::IRttiHelper* derivedExternal = classData->m_azRtti;
// returns true if derived
derivedExternal->IsTypeOf(iTreeGeneratorUuid);
answered 3 years ago
0

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

answered 3 years ago
0

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.

answered 3 years ago
0

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

answered 3 years ago

This post is closed: Adding new answers, comments, and votes is disabled.