# NPC Animation Blueprints and AI Behavior Trees C++

**URL:** <https://forums.unrealengine.com/t/npc-animation-blueprints-and-ai-behavior-trees-c/1234939>\
**Category:** C++\
**Tags:** behavior-tree-task, unreal-engine, CPP, question\
**Created:** [July 20, 2023, 4:47pm UTC](https://forums.unrealengine.com/t/npc-animation-blueprints-and-ai-behavior-trees-c/1234939 "2023-07-20T16:47:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krishna\_Chaithan1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Krishna\_Chaithan1](https://forums.unrealengine.com/u/Krishna_Chaithan1)\
**Post date:** [July 20, 2023, 4:47pm UTC](https://forums.unrealengine.com/t/npc-animation-blueprints-and-ai-behavior-trees-c/1234939/1 "2023-07-20T16:47:03Z")

</div>

Hi, I’m trying to create an WolfAI( using C++). These are the steps I have followed

i) Created a new C++ class for Wolf AI…derived from Character class.  
ii) Created a new AI-Controller C++ class. And added AIPerception Component to it… AI-Controller is handling the logic for OnTargetDetected(AActor\* Actor, FAIStimulus const Stimulus) and running behavior tree.  
iii) I have created Custom Behavior tree tasks and Services in C++…

My question is that , how to access the AI’s AnimInstance and update values of variables so that the animation state changes (from Idle to Running) from Behavior tree tasks(C++)?  
I tried in this way , and created some public functions in AnimalAI class for setting/updating speed ,but still no use

Super::OnBecomeRelevant(OwnerComp, NodeMemory);  
auto\* AnimalAI = Cast(OwnerComp.GetAIOwner());|  
auto\* Animal = Cast(AnimalAI-\>GetPawn());|

The other issue I have observed is that… when I try to set MaxWalkSpeed of character (AI wolf) from BTService(Created in C++) the NativeUpdateAnimation() in AnimInstance is stopped working.

Can anyone tell me where i’m doing wrong. Or is there any other approach?

Thanks.
