Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How can I get the nearest actor and store it's array index?


I've been struggling with this 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. This is what I have so far, http://i.imgur.com/MqlU8TK.jpg

I am not sure if this is the correct way of going about what I want to achieve. This is a Task blueprint, in case anyone is wondering.

Any help is much appreciated.

Product Version: Not Selected
more ▼

asked May 12 '14 at 12:57 PM in Blueprint Scripting

avatar image

1 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Try using a sphere overlap that covers the area you want the AI to search. Then set the Actor Class Filter to make sure the overlap node only looks for objects of the class you are looking for.

The sphere overlap will output an array of actors, so feed that into an Add node with your Array Variable attached.

Then, do a ForEachLoop on the array and pull the distance from the AI to each cover. Create a Distance Variable and set it to a very high number. As the loop looks at each cover's distance, compare the distance to the Distance Variable. If the new distance is shorter, set the Distance Variable to be whatever that new distance is.

Here is an example from my project:
alt text

In your case, you may also want a second Variable that sets to the Index of the For Each Loop and only does so when a new shortest distance is found. That way you can reference that variable against your array and get the index of the shortest cover.

That should get you started. I haven't touched blackboard yet so I am no help there, but it should just be a matter of inserting somewhere in the mix.

more ▼

answered May 13 '14 at 11:00 AM

avatar image

1.8k 131 68 110

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi !

I want to do the same thing and i have the same blueprint than you but... How it's possible to get the array index of the actor ?

more ▼

answered Apr 22 '16 at 06:52 PM

avatar image

Fabian Delcourt
5 3 7 9

avatar image Nick Jackson Apr 24 '16 at 01:50 PM

You might want to post your own question.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question