how can i make ai only attack player instead of every character it sees?

im working with behaviour tree and i have made a ‘attack’ task that should attack when it sees the player, but the thing is, i need to have 3 ai’s attacking when it sees player, problem is, it attacks the other ai’s and player and i want the ai’s to only attack player when it is seen.


this is currently what the ‘attack’ task is looking like inside of it. how can i make it only attack me(player)?

Hey @emir143!

So what I would do is use a “Player” and “Enemy” tag on all of the characters but… I can’t really help tell you if that would work here because all this is a picture of is an anim montage…

Wherever your sensing system is, if you show us that we can help you!

But basically, give them actor tags, use “ActorHasTag”, and plug that bool into a branch :slight_smile:

when you say ‘sensing system’ do you mean the AIController? if so

and also when you mention ‘tags’ do you mean the component tags?

Close! What I meant specifically however is how the AIs are gathering information about the environment, which in this case is AIPerception!

So you’ll open up your player first, as long as the enemies and the player don’t use the exact same bluprint this will work.

Click the root of your character in the components window, and then in the details window for the root you want to search “Tag”. Add an Actor Tag of Player (Make sure to not leave a space). Compile your player BP, close it.

Now we go back to your AI controller. Off of “On Target Perception Updated (AIPerception)”, take that actor pin and use “Actor has Tag”. Put your player tag in, make sure it is spelled the EXACT same, and it is case sensitive and space sensitive as well.

Plug that into a branch before the branch you already have, run through on true, do nothing on false and you’re good! :slight_smile:

If you have any issues let me know!

idk if this will make it more difficult but the ai’s is a parent to ‘Character’ and so is the player

Do they all use the same blueprint, but with different controllers?
If you’re saying they’re all Children of “Character” that’s ok. As long as the player isn’t the child of the enemy, or the other way round, or they’re the exact same blueprint with different controllers.

But if they ARE the exact same with different controllers, you can use “AddGameplayTag” on Begin Play on the PlayerController, using the possessed pawn as the target.

what i remember doing was i duplicated the player and changed all the blueprint, so the player and the ai’s blueprint looks different.

and the ai’s have different controller.

i tried with the tags but it didnt seem to work

(ai controller)


(thirdperson blueprint )

also i have ‘senses config’ with AI sight, was it that you were talking about earlier (its in AI Controller)

You have it set up exactly the way it’s supposed to be minus one thing! Component tags are different from actor tags. You need to tag the root to make it an “Actor Tag”. Like this :slight_smile:

ok by the looks of it, it started to work when i disabled enemies and friendlies in ‘Decetion by Affilliation’. So tags saved me.

Thank you for helping :slight_smile:

1 Like