How to play a particular animation for AI?

Hey Guys! I’ve made my AI, which works ok for now. I want the AI character to melee attack on the Player. I got the task setup for the attack and right now I’m just using a print String node to debug when it is attacking.

But, I don’t know how to play an melee attack animation on a particular event. I’ve very limited idea as far as animation is concerned. I’m using the mixamo characters right now as my AI and their respective anim blueprints. They have a sword attack animation.

How can I play this animation. Any Ideas?

Please Help. Thanks.

Exactly like you would for your player character.

You define it within your character blueprint which will be possessed by your AI controller. This one acts exactly like your normal player controller with the difference that you define from begin with when he does what.

You simply replace the input with a Behavior tree and all that stuff.

So you would attack by running a “Attack” task in your Behavior Tree. This one triggers a function within your character which then plays the animation, applies forces, damage or whatever you need.

@Erasio You mean I should create a custom event inside the character event graph which is called by the attack task?

@Erasio that means creating blueprint interface is the best solution?

OK…Thank you very much for your time

Well you could do that. Or you could do a function.

Blueprint Interfaces might be a good idea as well but yea. Basically you have your character which handles all animations (as they only apply to this single character. If you’d insert a second one you couldn’t use the same AI controller if you’d define it in there which would miss the point of it a little :wink: as well as applied damage and all character specific things.

Then you have either your player or an AI calling them as needed.

It really depends on how you would like it to work.

Each way works. It’s more a question of which way you prefer.

I haven’t come across performance differences so they are (if there are any at all) fairly small, So far I haven’t come across “best practice” usage guide as well so I can’t tell you what’s standard but in terms of functionality each one works just fine.

@Erasio I’ve tried it but the attack animation keeps playing, even if the player moves away.

Have you tried using that animation for your own character?
Is it only once there when you press the button?

And if not have you looked on the Behavior Tree while it’s running? Is it stuck or running as expected?

I solved it already…but thanks for the reply anyways…there wasn’t any task that stops the attack animation in the behaviour tree. So, I added it to one of the services and it worked perfectly.

Guys Can U please help me with bluprint
I need bluprint similar like this for ai

I am making game for boxing i hav all punch, kick, hit idle animation
I followed Introduction to Third Person Blueprint game - 1 tutorial and
i gave character punch and kick ability

i hav no idea how to work with ai now do u bluprint where ai will attack player
if player hit ai then ai will react on

please can u share bluprint with me

Hey there,

this is a really big topic and we already got plenta of Tutorials for that. You will want to use a Behavior Tree that reacts on certain events and changes the AIs States. For a normal AI (Shooter AI) this would be something like changing from State “Searching” to “Chasing” when he finds an enemy.

For your Boxing Ai this could be something like “Attack State” → “Def State” if the enemy punches several times or if the AI gets damaged at all.

To get further into this i recommend you to watch Video Tutorials for AIs.

They won’t cover your specific Boxing problem, but if you understood how this works, then you can easily recreate your own BTree for a boxing AI.

https://www.youtube.com/results?search_query=ue4+behavior+tree

thnx i will try :slight_smile:

Will u make tutorial on ai?
i hav short deadline project from company
here in our city no one game developer who can help me
please be in contact buddy i will need ur help
u can contact me if ur wishing too work on this project

Whats your work flow for creating the incoming task " triggers a function within your character which then plays the animation," im trying really hard to find an example

You could take a look over here at the behavior tree quickstart guide.

https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/QuickStart/

Basically you handle animations in your anim state which usually reads out something like velocity, is in air or whatever. Those animations always get played if that happens. You can also add custom calls to specific animations and all that good stuff.

Take a look over here at how to set up your character to use all the cool UE features:

Also the content examples are a good place to take a look (which you can download via your launcher)