I’ve been struggling with for a couple of days now. I think I have the logic set up for it (below), but I’m not sure how to implement a couple of steps with blueprint.
I am trying to implement a cover system. The AI searches for the nearest CoverNode blueprint (within a radius, preferably) and returns the location of that cover node to Blackboard. Simple right…?
/*Logic for how to get the nearest CoverNode and return it’s location to Blackboard (no radius implemented yet.)
Get an array of all actors of CoverNode class
For each, get location,
Get the location of the AIPawn
Compare the location of the AIPawn with each CoverNode location
Find the smallest value (i.e the nearest)
Store the index of that CoverNode as a variable (BestNode)
Cast to the Node array with the index of BestNode and get location of that node
Set blackboard key
*/
I’ve not used arrays much before, so I’m very unsure how to get the index of a specific variable in an array, or how to search through them.
is what I have so far,
Thanks for the help.
The array index in the ForEachLoop did indeed give me what I wanted. But strangely, it didn’t work the first time I tried it. I might have missed something, or it may have been a bug (always stored index 0 as the shortest distance). I closed the editor and rebuilt the blueprint and it started working correctly.
How would I go about getting the actors I need?
I see there is an ‘Actors to Ignore’ input, but not an ‘Actors to Include’ (ignoring every other type would end up as a massive list). The ‘object types’ input of course doesn’t allow actors.
Sorry to ask, I can’t find any documentation on this.
I’d extract the actors I need from the Array that was made from the Sphere Trace…
use the “For EachLoop” after the Trace and “Break Hit” from the ArrayElement on it…
Create an Object array for and add the “Hit Actor” to it from there “Filter Array” by whichever Blueprint Class you’d like…
From there continue on and Check the distance of the objects in the new Filtered array…
I’m no pro so I won’t be surprised if there’s a better way but should get the job done…
I was wondering if maybe you could help me. I’m trying to implement a similar feature but as soon as I add in more than one NPC, the distance search fails. Here’s my network:
When there’s one NPC in the scene it works fine, but if there’s two, then it always returns a fail state, as if it’s getting the distance of all the NPCs from the player and not just finding the nearest NPC.
Hi, I realize is a old thread but for anyone stumbling across the issue with **TorQueMoD**´s implementation is that the for loop ends with a finish execute. means that the RecieveExecute will only ever be able to loop through one iteration of the ForEachLoop. Instead he should en with the FinishExecute from the *Completed *node of the ForEachLoop.
As for **mikesdav**´s distance calculation loop; It works and works well. However, for those that get the issue of no returning actors it is important to set the inital value of “LowestFloat” variable to something pretty high since will be the first comparison. If it is set to default 0 nothing will ever match as lower distance. The initial value of “LowestFloat” can therefore be interpereted as a maximum distance check. Anything further away than it´s initial value will never be accepted.