How to get AI to follow closest Pawn of Type?

So I am trying to create a scene where a bunch of doe follow a buck along an open range. I want the doe to follow the closes buck in their AI sight (which is simply set to 180). I have just started learning Behavior Trees, and this is currently as far in the task “GetBuckLocation” as I could get wHAT posted by anonymous | blueprintUE | PasteBin For Unreal Engine. I don’t know how to get the closest buck as the vector location. Any help is appreciated and visual examples are most desired.

If you need more information I will give you all you need. I am hoping to use some of this logic to have humans find campfires and gather around them, and other searching tasks.
Thanks.

This is how you can decide which Buck is closest, then add your script now that you have selected the closest buck. This would go in the Doe BP.

Forgot, to use this in a blackboard you would need to get a reference to the “Doe” running this BT and that is what you would hook into the top pin of the “Get Distance To”. So add this script to a BT Task

I’m sorry, I am a little confused. I already have a SelfActor in my blackboard, Can I use that? And if so, how do I bring a blackboard key into a task? I have only set keys in tasks not retrieved them.

Whatever your “doe” is that is what this BT is supposed to be running for. So if “self” is the doe then yes use that. As for “getting” blackboard keys, you would need to use the node “get blackboard value as…” then find the one that is the same type as your variable.

that link doesn’t work FYI. And I would need to see the tasks themselves to be able to help figure out why they aren’t progressing.

Ok so I got it working, I combined my code and your code into one task. However, It will fire for a few seconds and then the prey will stop moving, and the BT will get stuck on that task. I’m wondering if I made some stupid mistake in the Task. This is the Task. Out of context it makes no sense, but this BT is for the Doe, The Predator is the Buck/Pack Leader. It needs to chase the Predator.

I fixed the link, The set focus is just an Execute, set cast to ai, set focus, finish execute. Move to is just going to the location grabbed in the one at the link. Clear Focus is set up the same way as Set Focus, and Find Escape route is just an AI Move To random location.

Try hooking everything after “set closest predator” up to the completed pin of the loop because you really only want that to execute once… once you’ve found the closest buck not just a buck closer than the previous one

Screen shot the actual tasks. Because it looks like once the move to is complete and the behavior tree falls back up the top if nothing changes with the “can see player” decorator you would be done executing.

No, that didn’t fix it. I think the problem is that it checks the location once, moves there, then doesn’t check its location again.

EDIT: In case I didn’t mention it before, the Buck it follows is always moving. If I set them to follow an actor instead of a Vector, they don’t move.