AI tasks to get actors In map Not working :(

I followed A tutorial to learn how to get the nearest actor of type in a map. UE4 Get Closest Character to Player (Unreal Engine Tutorial) - YouTube
And I tried to turn it in to an AI TASK so my simple AI bots will find all the capture points I place in My map and pick the nearest one then move to it.

I also Made a pick random Capture point task.
Unfortunately None of them work and my AI just stands in place.
My nav mesh is all set up and If I use the get random location and move to its working fine , But these custom tasks dont.
Can anyone spot why they are note working.

Get nearest Capture point

Get random capture point

Can you be a little more specific. What exactly is not working? The target’s selection, the blackboard values, the behaviour tree, …
The print strings, to they print the right target?

One little remark on your bps: with “get all actors of class X” you already got an array. Why the for loop to read and set the “capture point” array? Why not, set “capture point” directly from the “get all actors of class X” output pin:


Also, in the get the closest task:


Shouldn’t it be:



In the BT, tasks selected, did you set the blackboard key in the details panel (MoveToLocation for the first and Location for the second):


The top bit is just a leftover from me doing trial and error trying to trouble shoot it if you look at the second pic I made the right choice like you suggested.
But as for the extra loop that was what the tutorial I followed did. And what part thats not working is the characters not moving even thought I can see to location printed to screen. I am setting the BB key to the target location.

You see it printing. How about the values in the BB? Do they get the right value?


Also, when executing, what happens in the tree? I mean, it executes the point selection task and then the move task or it just keeps running the selection task or it’s all over the place?

I remade the random selection Task and made it as minimal as possible.

And in the game screen the random selected Capture point is selected in blue and the world location is in yellow. But in the BT I can see the task is static and not moving to move to.
I have to put a do once node in the task otherwise its constantly running and spamming the random selection on the screen while the BT is task is flickering due to constantly running.
I have the finish execute node so Im not sure why its not moving to move to. If i swap the task with select random location in nav mesh it works.

Your code looks good.

So, remove the “Do Once”.

The flickering is usually because of an invalid value, which you could watch if it’s in the details panel during execution:


  • So, is your “MoveToLocation” variable *Invalid *or does it has a valid value?

  • Is your “MoveToLocation” key variable public?


  • Have you also select “MoveToLocation” not only in the “MoveTo” task but also in the “OBJECTIVE” task?


Everything Is as it should be and all it does is loop between the task and the move to task without ever moving. I am starting to believe this method will not work no matter what.
Just for testing purposes I created this

and set the same move to location BB key. and swapped it with the Task in the BT. and it works right away . so its defiantly something to do with the code imo

Well, if *MoveToLocation *has a valid value in the BB (so, it can’t be from the code - the code must be working as expected, afterall, it printed the right results, right?) and both MoveTo and OBJECTIVE tasks are set to MoveToLocation, then there is no reason not to work.

I can’t see any problem. Perhaps someone else can.

Just had some luck . I started to add ontop of the test code above and was surprised to find that Its only working with the Vector + vector .

If I remove the vector + vector it stops working, even with the actor loc plugged directly in the the BBkey selector . or even as a promoted variable.
Strange they don’t work unless I add the vector + vector
Now I will Test it with the All Actors off class and not just a single

Yep its working :D:D:D.
Been trying to solve this ALL bloody day.:mad: And the solution was so simple , even if I still don’t fully understand why it works like that and not directly from the actors world location or a promoted variable of it.
Well at least others are going to gain from my struggles, :wink: