What does AI do after it kills target

Hi everyone! I am trouble making AI go back to its regular state after it killed a target. Once the AI kills a target everything fine but when I go up to the AI nothing will happen if I damage the Ai then it will finally notice me. Here’s what I am doing if enemy health > 0 then chase the enemy if false then what do I do.

As TorQueMoD said, AI can do what ever you want it to do, that’s up to you. It’s all about managing the state machine/blackboard.I like to make a high level plan for the way I want my AI to work on paper before I try and code it, so you can plan it’s states, it’s a good way of making you think about every state you’ll need for the AI’s brain.

One thing that I find works well for making sure the AI doesn’t get stuck in a non active state is to manage that with a service that ticks along at a pre-determined rate (should not be every frame) and that sets your state, so if the AI doesn’t know what to do next then on the next service tick they can have their brain jogged to pick a new task to do if not doing anything currently.

If you need a bit of help getting your head around the basics of how AI works in UE then I would suggest looking at some of the unreal learning course available like this one.

There’s no pre-defined thing that A.I. does after killing its target that I’m aware of. Can you show us your AI code like blackboard etc.?

What I did here in my code is check whether or not my AI’s target health is above 0 if true then the AI will chase that target if false then what do I do? When the false executes my AI stands still and ignores all enemies that are in front of it. Sometimes it sees something but most of the time the sight ignores all targets that is my problem I want the AI to lose sight of its target when the target dies so it can see other targets out there.

Also here is my behavior tree.

I’m not trying to be offensive in any way when I say this, so please don’t take it that way. I would spend some more time familiarizing your self with the logic and workflow of blueprints in general before trying to tackle A.I. I’ve been coding in Blueprint since UE4 was in Beta, and I still find A.I. difficult. I’d recommend checking out YT channels like Tesladev, Matthew Wadstein, Matthew Palaje and CodeLikeMe to help you get a better grasp on Blueprint in general.

That being said, first thing I would do is connect a print string message to your IsNotValid pin on your first check there. There’s been plenty of times where I’ve assumed that the target itself is valid, only to find out that it’s not. ALWAYS connect something to both pins if only to check to make sure your code is working properly. It’s the easiest way to debug BP.

Secondly, I wouldn’t run a check to see if the player is alive from your AI. This is just going to bog things down because it will have to check constantly. What I would do is code a simple Health/Death system onto your player (or any other potential target) and then when checking to see if the player is still alive (which you would do only when the player receives damage) you could send a message to all other actors who are set to listen to that message and use this to update the player’s life status. Also, from the OnTakeAnyDamage event, you actually get access to both the actor who caused the death as well as the player controller attached. This is a fantastic way to be able to cast between the player and the ai in a really efficient manner. After the player’s health drops, you could get the player controller or the actor itself who caused the death and run some custom code like telling it to return to a specific point in the world.

Thirdly, and this goes with my point above, your A.I. is likely standing there and doing nothing because it’s waiting to find a new target. Rather than letting it find one on its own, you should force one. This will guarantee that it won’t just stand there doing nothing. After the player dies, pick a location in the map and have them walk towards that location. Then along the way, if they see another target that they can engage with, they can break off from the walk-away command and engage with them.

Here’s a look at how I would handle checking to see if the player is dead:

I was able to figure out what went wrong all the code I did was correct and fired the right way but there was one thing I needed to do that I did not even know existed… Max age.

Glad you figured it out :slight_smile:

There’s a great tutorial series on UE4 ai on udemy that goes on sale several times a year. I bought it myself, but haven’t gotten more than a few vids in yet.