Download

Class Child Casting

Hi. I hope this is the best forum where to post this. Anyway I made a character class where I have a lot of stuff. I made 4 childs (so for example 4 different characters with similar settings) and all was working good till I tried to cast to animBP in the main class. The thing is I need to cast EXACTLY to the child Bp’s animation Bp to get some variables so for example if the child BP is called Johnny I need to cast to JohnnyAnimBP but I don’t know if this is possible from the main class. I made a animation bp variable that I could set up differently for every child but I still don’t know how to make a proper cast to the right Anim Bp. I know this is quite confusing so If you didn’t understand just ask and I’ll explain the best I can.

Thanks in advance :slight_smile:

Hi Fiorenzone,

I think you can make an interface BP class for your animation BP.

So your JohnnyAnimBP can implemnet that interface, and your parent class can get the variable without you specifying which animationBP it is using.

(If you have access to the character’s mesh in the main class, you can definitely cast to the exact animationBP you want by using mesh->GetAnimInstance()->CastTo<ClassName>()

to get the exact class you are looking for, but I think it is a good practice to use interface for further extension and maintenance of your code.)

Hope this help your problem :slight_smile:

Thanks for your answer I’ll try that interface feature. I also have access to the char mesh but for <ClassName> do you mean main class name? So for example in main class called characterBP I should do mesh->GetAnimInstance()->CastToCharacterBP() ??

Hi,

Sorry for the vague answer, I meant to say mesh->GetAnimInstance()->CastTo<JohnnyAnimBP>() in your main class.

But if you’re using interface, you can just do:

mesh->GetAnimInstance()->DoesImplement<InterfaceClasssName>() (if true then call the getter function you need)