x

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"

How do I access an individual actor with multiple of the same actors on the same level?

I have one AI Actor that I want to spawn several of in a level and then access them individually to give them specific gear or even a name. I've duplicated them in my test level and have had success telling them all to follow me using 'get all actors of class' and then a 'for each loop' function with an array but now how do I just reference one? End goal I would like to open a menu and have a list of all my NPC team mates and access their inventories and loadout from there. The image I've attached is how my character gets them all to follow me and is the only reference I have to accessing them in game.

Product Version: UE 4.19
Tags:
blueprint.jpg (133.4 kB)
more ▼

asked Aug 16 '18 at 01:47 PM in Blueprint Scripting

avatar image

HP Laserjet 400
1 1 1

avatar image HP Laserjet 400 Aug 17 '18 at 02:44 AM

Thanks for the answers, I've added a setName text variable(just a guess at which type) that FittFrasen suggested and I've changed the other blueprint on my third person character to where the 'get all actors of class' is on begin play but I am not quite sure where to hook up the 'get' and 'find' nodes.

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

2 answers: sort voted first

since you mentioned your end goal is to have a list i would simply add them all to an array. to do this i would use on begin play get all actors of class then right click the array return pin and promote it to a variable. this way you will have a list of all the npc characters and you can add and remove from the list as needed. this is also a better method than using a get all of class everytime you want to do something, instead you just use the list thats already mode so its more performant.

i should also mention that to get just one from the array you would use a get node. theres also nodes such as find which could be of help. once you setup your widgets for your inventory and all that though it will be even easier since im sure you will have something like a scrollbox with a button for each npc.

more ▼

answered Aug 16 '18 at 02:11 PM

avatar image

ThompsonN13
10.1k 33 10 23

avatar image HP Laserjet 400 Aug 17 '18 at 02:44 AM

Thanks for the answers, I've added a setName text variable(just a guess at which type) that FittFrasen suggested and I've changed the other blueprint on my third person character to where the 'get all actors of class' is on begin play but I am not quite sure where to hook up the 'get' and 'find' nodes.

avatar image ThompsonN13 Aug 17 '18 at 04:20 AM

a get node is to access one object from the array. for example if you wanted the third item in the array then you would take the array and connect the get node and set the index to 2, the get node would then output a reference to the third item in the array.

the find node is just a way to search through an array to find the index where an item is. so lets say you had an array of characters and wanted to find where mario was in the list, then you would have a reference to mario and connect it to the find node and it would output the index that mario is in.

its one of those simple things thats hard to explain.

the get node is the one you need to be worrying about in this case since it allows you to get a specific item from the array.

avatar image HP Laserjet 400 Aug 17 '18 at 05:47 AM

Works great! thank you for clearing that up for me! I still haven't tried the find node yet but I'm sure that won't be too difficult

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

You could simply create a function in yor AI_BP called setName and have a variable there that you define. This way when you use for example your for each loop you could access their name either directly or through a get function. For this to be of any use you would need a way to generate random names though. In my own project i have a enum with names and then i generate a random number to give my AI's different names. I am not able to access my computer with the project at the moment but if you need further explination I could show you a printscreen later.

edit: Accidentially added this as an answer to your qustion but i realize it's more of a comment

more ▼

answered Aug 16 '18 at 02:34 PM

avatar image

FittFräsen
23 2 3 8

(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