# Set Animation Blueprint to Character from C++

**URL:** <https://forums.unrealengine.com/t/set-animation-blueprint-to-character-from-c/138186>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 14, 2020, 4:37pm UTC](https://forums.unrealengine.com/t/set-animation-blueprint-to-character-from-c/138186 "2020-02-14T16:37:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asierta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@asierta](https://forums.unrealengine.com/u/asierta)\
**Post date:** [February 14, 2020, 4:37pm UTC](https://forums.unrealengine.com/t/set-animation-blueprint-to-character-from-c/138186/1 "2020-02-14T16:37:33Z")

</div>

I am trying to set an animation blueprint class to a character from C++. How can I do it and what is the best way to do it?  
Thank in advance 🆒

---

<div class="post-metadata">

**Author:** ![sivan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sivan](https://forums.unrealengine.com/u/sivan)\
**Post date:** [February 15, 2020, 11:29pm UTC](https://forums.unrealengine.com/t/set-animation-blueprint-to-character-from-c/138186/2 "2020-02-15T23:29:11Z")

</div>

you can set new AnimBp of a skeletal mesh component, not the character, so add this code to your skeletal mesh component class, or add GetMesh()-\> before the function calls:

// as I remember this is needed to get it work  
SetAnimationMode(EAnimationMode::AnimationBlueprint);

// I store the AnimBp classes is an array of UAnimInstance-s for each weapon, so select the new class to use  
TSubclassOf\<UAnimInstance\> AnimBp = AnimationBlueprintClasses[WeaponUsed];

// switch to the new AnimBp  
if (AnimBp)  
{  
SetAnimInstanceClass(AnimBp);  
}
