Identifying specific actors among many

So lets say I spawn 200 actors out into the world, each with a specific vector. How do I get any given actor from that group?

I can store it’s vector when I place it, but how do I get back into it?

Get actor at location x/y, run function B?

Or, store each actor in an array, and link the actor index with the corresponding vector index? So I call a vector, get it’s index, run that index in the actor array, and then run the function on the actor that is returned? Does each actor have a unique ID once spawned?

Anyone able to help?

If something collided with my actors, I could call the actor’s functions, but that isn’t really appropriate for my game.

Is a trace what I need?

How do you “Get actor at Vector and run its functions or gather its info.” ?

Second option is good.

after, you can check the list to look for the actor more close to the vector.

btw, It is importan say more info when ask for help, the answer can change dramatically if you spawn random or spawn in rows.

Sorry, yes these actors are all spawned in specific locations which is all stored in an array.

So trace is my best bet? I will look into that, thanks! :slight_smile:

I say arrays not sure but sound good.

store each actor in an array, and link the actor index with the corresponding vector index? So I call a vector, get it’s index, run that index in the actor array, and then run the function on the actor that is returned? Does each actor have a unique ID once spawned?

I had that thought as well with the arrays. Does each actor need a unique ID, or if I spawn 200 instances of the “same” actor, do they all have separate IDs?

If I can store them in an Array as I create them and reference each at anytime based on it’s index I think that basically fills my need.

If I need to impart some unique ID to each actor as I store it, how would I do that?

there is loop ForEach, and if you have array of actors you can reduce it to array of actors of some type (forgot that function name).

So for eg. you want to spawn 200 health pickups, some have 30hp some 50 and some 70hp.
You make health pickup parent class, that has 0 hp (and some dummy arrow or sign mesh for where its placed)
then you make 3 child classes with 30 50 and 70 hp (those should have your pickup models and emmiters)

to get all pickups you make foreach loop and point it to parent class, you get array of all pickups you placed.
then you can copy this array, and select only single child class.
Or you can do for each and point to child class, and you get only that subclass array.

If you have only one kind of pickup/actor, just do for each for its type.

However don’t do this on every tick. It will slow down everything.
instead make “picked it up!” event for parent class, and do your pickup logic only if that event was fired.

To get vectors (locations) get reference to item in array then get its transformation.

They will all have unique ID (or rather pointers, that point to allocated instance of actor.
You do not need to remember them in separate array, they all are stored in level (like all actors).
You can ask your level blueprint to make array of all actors of selected class.

But if you spawn bunch of different meshes they all will be of static mesh class, so picking up all static meshes will give you all of them in level.
It is better to make own simple blueprint that holds mesh you want, then you can search for that blueprint class objects.

Thanks. I will probably do a lot of that at some point, but right now I have a more specific need.

I have the vector of each instanced actor.

What is the best way to interact with a specific, individual instanced actor given only that information? Get Index/Vector, and then…?

I tried loading them all into an actor array but they all have the same name. If I could just say “Hey you, destroy yourself!” then I could probably figure everything else out from there, but I can’t seem to find out how to say “Hey you”.

Well there is way for doing it your way.

You make custom blueprint, lets call it “destroyable_BP” , that can send event “I_Am_Hit”. And can give pointer (reference) to self.

You need to make variable “destroyable_pointer” inside player character (easiest to reference),
When players hits “destroyable_BP” it sets “destroyable_pointer” inside player to its own reference (self). and sends “I_AM_Hit” event out.
To set that “destroyable_pointer”: inside “destroyable_BP” get reference to player character, then get node “cast to Mycharacter” (or whatever is your character bp called).
Now your player knows that he hit destroyable (listens to “I_am_hit” event) and its reference.
With that information you can tell that single instance of “destroyable_BP” to kill slef or ask it for its location etc.

Or you can do it all with interfaces. But for single pointer i find its easier to just pass references over.

There will be no collision between my player and the actors. I will have click events on each actor at some point, but before that I need to be able to reference my actors during map generation.

It sounds like I need a way to “Hit” my actors without actually hitting them.

Is a single line trace the best option I have for finding an actor at a specific vector and calling it out? Or is there a better way?

Having watched the excellent tutorial below, I see that single line trace is what I need. If anyone knows of a better way to interact with an unknown actor, please let me know.

Instead of calling the trace on right mouse button, I will have to work it into my map generator and align the vectors properly. It may get called thousands, or even millions of times during generation, so hopefully that isn’t a problem performance-wise.