EQS: How to find the AI that is the closest to the player

How did you hook the "OnQueryFinishedEvent to the bind event? I can’t seem to bind it after adding an input

Oh, sorry i got it!

An easy way is to drag from the retun value pin of the Run EQS node and search for “assign” it will automatically create an event with the correct signature. Another way is to drag from the delegate pin in the Bind Event node and search for Add Custom Event, it will also automatically create an appropriate event

1 Like

Thank you! I got it set up, and now its finally printing. It prints anything that I’m near it seems, but when I go near the AI its only printing the characters display name.

EDIT: it does on the other hand print other blueprints. Just not the AI and “closestAI” is still set to none

Again, in your EQS, make sure the Generator Context is set to
image
Also make sure that you have selected the parent class of the AIs

And the “distance” to the ai context?

No distance should also be querier

Both is now set to querier. It prints the character name, but now the AI doesnt behavior tree is stuck at the root

Is the “searched actor class” supposed to be set to the master AI class? Sorry if i misunderstood

oooh i tested with the “searched actor class” set to the master class, and now it prints the AIs and their display name changes when I get close to one or the other. I must have forgotten about it when reading

Yeah was about to say. Does it work then?

It prints properly now, but it still runs red and the behavior gets stuck at the root again :sweat_smile:

Heres the node again

Where does the flow stop in the character blueprint

Seemed like I had some more disconnected nodes. I must have read your image wrong again. It works perfectly now :sob:

Thank you so much! I really appreciate you!

I didnt have the nodes between “UpdateClosestAIKey” and “get valid” node connected. Which is why it didnt work. But you were right, your blueprints works

And sorry for the long thread! I’ll summarize it all incase someone needs the same answer:

  1. Check what this comment is replied to and make the blueprint in the character blueprint. Also hook up the event at begin play or another desired location.
  2. EQS should be "actors of class: generate set of actors of [Searched Actor Class] around Querier.
  3. Set the “Searched Actor Class” to the master BP of all AIs in the generator. Also make sure the “Search Center” is set to “Querier”.
  4. Distance test looks like this:
  5. Then do the check with “Compare BB entries” on a selector that looks like this in the end. (Closest AI) is set to object in the blacboard key:

That should be all of it summarized I think

Thank you again Zeaf and Kaidoom15 for helping me with this :smiley:

4 Likes

I’m glad that it works :slight_smile: I’m thinking about a different, a bit better solution, that is less prone to errors now

1 Like

Slightly better solution:

Add an event dispatcher OnClosestAIChanged in your character:
image

The graph is now updated:

Create a new BTService:
image

The service should look like this:

Add it in a relevant node in your tree, create a new boolean blackboard key and make sure to select it in your service. The IsClosestKey variable needs to be instance editable
image

Then in your BT add a blackboard decorator to your Closest AI subtree root, and check if your boolean key Is Set

That should do it, it’s event driven and a bit better, and won’t have any issues if an AI is destroyed while it’s the closest target for example

1 Like

I believe with this you don’t need the instance sync anymore right ?

That’s correct

2 Likes