How do I create a Stun abliity?

I am fairly new to unreal and working on creating a stun ability but I am not sure where to being I know I have to working in the behavior tree but now sure what specifically I am supposed to do, if I could have any help or pointers on where to go that would be great.

I’d use a BPI to send the stun state from your player character to the enemy (when stun ability is used) and use stop all movement immediately, play stun animation and then have a delay for the duration.

I’d use a BPI to send the stun state from your player character to the enemy (when stun ability is used) and use stop all movement immediately, play stun animation and then have a delay for the duration.

In the behavior tree you would check for stun state active and if it was, do the stun event.

okay I also have never done a behavior tree before so this may be a bit difficult for me is there anything you recommend

Do the official tutorial first to get an understanding of the basics:
https://docs.unrealengine.com/en-us/Engine/AI/BehaviorTrees/QuickStart

to be honest I don’t really understand what you are saying nor do I have any idea on how to create an ability with my character to have it affect the enemy

Fair enough. So lemme give you an example. I’m going to assume you don’t have attack animations and capsules to utilize.

So first thing you want to do is add a sphere collision to your playable character blueprint. Just click the mest on the left side in the blueprint, click add component and choose sphere collision. Scale it up in the viewport to a decent size, say 50 or so just to have a good hit.

Next, go into your character blueprint and with the sphere selected, scroll down until you find “on component being overlap”. Click the plus sign, drag out the “other actor” pin and choose promote to variable. Call that variable “Target”. Then right click somewhere else, type in “1 keyboard” and choose the number 1 keyboard key.

Before we move on we need to do something you will find very helpful later. Go to your content browser and right click mouse over blueprints and create a blueprint interface (this is so that you don’t have to cast to a specific enemy, all overlapping enemies may use this functionality). Call this blueprint interface something like “BPI_Event”. Open the blueprint interface and in the already created function, just rename it “Stun”.

Now go on back to your character blueprint and before we do anything else, we need to make sure your character can use that interface we created. So click class settings on the top bar, and in the interfaces tab on the left click “Add”. Select the “BPI_Event” and we’re good to go.

Now right click and turn off context sensitive, type in “stun message” and add that to your blueprint. This will message the function we are going to be using, ie triggering the event elsehwere. For “Target” drag in the “Target” we created. The result will look like this:

268083-stun01.png

Now, you go into the blueprint of your enemy character, and you add the BPI_Event to class settings like we did before. Then you right click and type in “Event stun”. That will receive the input from the message event and fire the function off.

Next I am going to assume your AI is working based on event tick. What you want is a way to disable event tick for a set amount of time, ie making the enemy immobile or “stunned” (can play a stunned animation if you want, let’s not focus on that now).

So, add a variable to your enemy blueprint called “IsStunned”. You drag it into your blueprint and choose “Set”. Then you drag the execution pin off your BPI function and make it set the value to true. Then right click and search for “Stop movement immediately” for Character Movement, add that to your graph after you set the variable. Then you add a delay node, set it to 5 seconds or so, then you add in a “Set movement mode” node with your character movement as the target and set it to navmesh walking. Then you set the “IsStunned” variable to false.

Now you want to but a branch after your event tick, the condition being “IsStunned”. If that is true, do nothing (or you can make it play the animation if you want). If it is false, connect that to the other behavior you may have. The result will look like this:

And there you have it. The enemy is now stunned for 5 seconds. Off the true branch from event tick (or before the delay node) you can add a play animation or play anim montage node if you want to play a stun animation. There are of course many ways of doing this and stunning several enemies will require some variations. I assume you will have some sort of ability to do the stun and then you can code a specific collision to it and have the enemy react by being hit by it, so you don’t have to set a target etc (this will only hit one in a group of many, for many enemies you’d want an array and add all overlapping actors to that array).

so this is what I have for my movement for my AI how can I adjust what you told me for this to work?