Why can't i dynamically load an animation BP in a packaged game?

All right,

Just in case anyone bumps into this problem, here is some working code to dynamically load animation blueprint.

The trick is simple: never ever use blueprint, instead, use the class Luke.

// get the blueprint class reference from the editor
FString AnimClassStringTest = "Class'/Game/mixamo/Heidi/IcloneAnimBP.IcloneAnimBP_C'";

// load the class
UClass* AnimationClass = LoadObject<UClass>(NULL, *AnimClassStringTest);
if (!AnimationClass) return;

// assign the anim blueprint class to your skeletal mesh component
Skeletal3DMeshComponent->SetAnimInstanceClass(AnimationClass);

And this is it :slight_smile:

Now if you want to your animation state through variables, here is the bonus.

Code a class inheriting from UAnimInstance to store all your BP variables (here i created the UYagCharacterAnimInstance class that contains the AnimTest integer).

Your animBP (here IcloneAnimBP) should be created in the editor inheriting from your own anim instance class (here UYagCharacterAnimInstance) instead of UAnimInstance

Then:

// Assign the skeletal mesh component instance to your own instance
UYagCharacterAnimInstance* AnimationBPInstance = Cast<UYagCharacterAnimInstance>(Skeletal3DMeshComponent->GetAnimInstance());
if (!AnimationBPInstance) return;

// You can now modify your variable (provided your anim BP, inheriting from your own anim instance class, knows how to handle this variable)
AnimationBPInstance->AnimTest = 42;
// This value will be passed to your anim BP and can  some state modification, etc.

As always, it might not be the best way to do this but it works.

All this is done in the PostInitializeComponents function in my code but can be put anywhere else, the point is it’s not in the constructor and is entirely dynamic.

I hope this helps !

Cheers

3 Likes