Getting an AI to clear their Target after killing them (simulating physics to ragdoll) using AIPerception?

I just recently started learning AIPerception and using it with Blackboard to make an AI capable of team vs team fighting -

I’m using On AI Perception Updated and Sight as the primary sense within the AI Controller. Upon an actor successfully sensed, that sensed Actor is set as a blackboard key called TargetActor and I made sure that the AI only sets a new target only if they don’t have a TargetActor set. Because my characters Simulate Physics when they “die” instead of using Destroy Actor, I set the dead Actors as “Downed” using Tags. Back inside the AI Controller where the AIPerception is, I then put a condition - if the sensed Actor has the “Downed” tag, they will set their TargetActor to None.

What I realized was wrong with that was that, instead of removing that specific “Downed” TargetActor, it caused my AI to wander around in Idle ignoring perceived enemy actors because they constantly sensed “Downed” enemies who were laying around. Thus, I don’t know how to remove the specific “Downed” enemy as TargetActor and get them to switch to a new TargetActor.

I am currently stuck on trying to make an Array that adds perceived enemy actors and removes “Downed” enemies of that each side uses to store TargetActors so they can switch targets to another perceived enemy once they kill their TargetActor. This is difficult for me because I don’t know how to integrate an Array into Blackboard and have that information communicated across all teammates.

I ask about arrays in blackboard here:

I want to ask - Are there any other methods I can use to clear the specific TargetActor with the actors using “Downed” tag? I’m not sure how to approach this at this moment so some tips would be greatly appreciated.

I based my scripts off of the Advanced AI Tutorial provided by Epic.

Thanks!!

Hi! so what i would do is, put all the sensed enemy targets in an array, then use a for each loop to decide who is your primary target, based on distance or whatever you want, and send it to the blackboard.
If your character kills the target, and its in “downed” state, you just have to get the array again,
use the Find node, to find the target in the array and remove it from it, the you can run the loop again to find a new target.
If you still cant make it work, let me know, and i make a few screenshots when i get home :slight_smile:

Thanks for the advice, I’ll let you know if I figure it out!

Hey! Sorry for the late response - I’ve been working with the array and managed to get it to store the first enemy seen but I don’t know how to use the Find node to get actors with specific Tags. I see that the Find node needs an Actor as input after the array but I’m not sure what to do with that. My current method just takes and stores a single actor and when that actor is dead, they remove that TargetActor, which works but the AI essentially has no memory.

So I have recreated what you were looking for. Of course there are many ways to get this result, but this is what i come up with.

So in your Character BP you need a Bool variable in my case ‘IsDead?’ this is what i use instead of the tags, couse its easy to pass it to the blackboard. You just connect this to the health, and when health is 0, you set this to true, and enable your ragdoll.

Then this is your AiController.
255889-
You need to add an AIPerception component to it, so your AI can detect targets.
Add an array with variable type ‘whatever your character class is’.
then set up the nodes seen below

with this setup you achive that, every single character your AI can see, will be saved in the array, when they get out of site, they are geting removed from the array.

After this you have to set up the Behaviour Tree

This one is pretty simple just so you can see.
First you need a NewTask ‘Get primary target’
This task will help your AI find a target to attack.

You can set up any logic in this, this is the most simple,your AI just going to get the first target from the list and set it as primary target. Sending it to the Blackboard

Then you need your Task to attack that target. again, you can set up anything here, fire a gun, or move your actor or anything.
This Attack task has 2 Blackboard decorators One of them will cheack if the Primary target is set, the other will check if the primary target is Dead.

And after this, there is the most important part, the service that runs every 0.5 sec and setting the bool variable of the blackboard.
If this variable is set to true, de decorator will abort the attack, and restart the sequence, so your AI will go for the next target, also removing the previous from the target list

2 Likes

This worked perfectly! Thanks for that detailed response, Evertoo.

By the way, do you happen to know a way to properly de-possess an AI after they have ragdolled so they take a minimal performance cost?

If not, thanks again for helping me out!

@Evertoo I know this is two years later, but can you please re-include the first screenshot of your AI Controller? It has been removed and just says ‘alt text’. Thanks.

There is also a node called ‘Forget…

Same as others, if it’s at all possible to get a guide to what you’re AIC Perception BP looks like, this is exactly the problem I’m trying to solve and I’m surprised I haven’t found any other post on other forums that seems to be solving for specifically this.