Setting blueprint animation class to a c++ pawn skeletal mesh?


I have imported from blender a 3D object with animations(not a character).
I have created a blueprint animation class for it, to run the animations.

I have created a c++ pawn class, added a skeletal mesh component in there, and I need to set an anim class for that skeletal mesh.

The problem I am having is getting the blueprint animation class reference to assign it for the skeletal mesh.

I have tried everyhing that is mentioned in this post:

But none of the solutions work.

The problem I am facing is that if I am using Constructorhelpers::FObjectFinder, it always tells me that can not convert my type to UObject.

I have tried:
static ConstructorHelpers::FObjectFinder FooAnimBPObj(TEXT(“AnimBlueprint’/Game/GameObjects/ObjectsWithAnimation/TrapDoor/TrapDoorStateMachine.TrapDoorStateMachine’”));
static ConstructorHelpers::FObjectFinder FooAnimBPObj(TEXT(“UAnimBlueprintGeneratedClass’/Game/GameObjects/ObjectsWithAnimation/TrapDoor/TrapDoorStateMachine.TrapDoorStateMachine’”));
And both give me an error saying cannot convert argument from UAnimblueprintGeneratedClas or AnimBlueprint to UObject.

and then I would try to do (my skeletal mesh component name is TrapDoor)
TrapDoor->AnimClass = FooAnimBPObj.Object;
to set the animation class, so that I could switch animations.

Unfortunately I have been unable to set the blueprint animation class to the skeletal mesh. It was very easy to set in in a blueprint pawn class, but I can not get it done using c++ :frowning:

Insted of hard coding assets to C++ make a settable property, this will make animation switching in editor a lot easier (As easy as blueprint already have… i mean it made exactly this way) by property editor without needing to touch C++ to do it. This is best practice to any referencing of assets in C++, it specially helpful if you create entire base class which will be root for many blueprints that have any form of asset usage. Using objectfinder should be last resort or if you really want to enforce in specific asset or don’t have a blueprint at all for that class.

Animation blueprint is blueprint, and same as any other blueprint it generates UClass while asset class UAnimBlueprint same as UBlueprint it self is just a “source code”. So in general there no real need to bind blueprint it self, insted try to get generated UClass.

Animation blueprints generates UAnimInstance class. so all you need to to make a TSubclassOf property with EditAnywhere or EditDefaultsOnly if you want to restrict it to defaults in blueprint editor:

TSubclassOf<UAnimInstance> SecondaryAnimation;

Now setting AnimClass is not enough as this varable is only for initlal animation class on component startup, as class need to be instantiated first and then set. Not to mention UE4 can not detect variable changes in C++. There different function dedicated for that which do exactly that, you should always look for set function instead of variable setting:

Aslo make sure to create null check for your property, so your code wont crash if it’s set a None in editor.

if(SecondaryAnimation) {


If you use C++ in UE4, in reality you extending engine it self by adding you module to already existing once inside engine source code and plugins, you got exact same power as any other module in the engine. All blueprints are based on C++ code, if you see something can be done in easy way in blueprint, there is way for your code to do the same, you jus simplely not aware of how to do it.

As for directly answer to your issue FooAnimBPObj is UAnimBlueprint it wont first in UClass of AnimClass variable, so in order to use class that in generates oyu need to first extract it from it, and oyu can get if from GeneratedClass variable. You will need to place that class somewhere so you will end up using property i made above either way. You also need to cast Object first to UAnimBlueprint in order to access anything from it to even set asset in property.