How to get access to actors that are spawned from an array

guys i have this spawn system, and I want to get access to each individual actor that was spawned. but i can’t do it the usual way cuz the return value is just an actor and i can’t cast it bcz its gonna cast every single actor that was spawned. whats the proper way to do this.

You need an array of actors, that will hold just about anything.

But, yes, you will need to cast when you process that array.

If you give a bit more details about what you’re trying to do, I can tell the easiest way to do it.

Do those actors have something in common or they’re really completely and utterly unrelated?

  • if they’re related: Inheritance / Dispatchers / Interfaces
  • if they’re unrelated: Interfaces

Do tell.

When you say you need access, what exactly do you want to do to the actor and from where? It might be as straightforward as registering a single dispatcher that sends the data away from the actor. Or establishing a Custom Event in the actor that will receive data.

You may not even need arrays for this, tbh. Impossible to advise without knowing what is really needed.

And if you do want to go the array way:

1 Like

doesn’t really matter from where

It REALLY does matter. That’s the whole point.

  • how do you know which of the spawned actor you want to destroy?
  • where is the event that will trigger the destruction?
  • how will this event trigger?

Why not just give us the scenario (you can change the Names of People & Places)? My absolutely least fav thing on AH is grilling people. :smiley:


Does the event destroy all spawned actors?

Calling the above Dispatcher would destroy all actors spawned this way. But you also say:

i wanna destroy the actor at some
point

…suggesting you have a very specific actor on your mind? Is that correct? If so, how do we know which one?

actors do have something in common, they are all inheriting from an actor which is where the code is done.

i wanna destroy the actor at some point, doesn’t really matter from where but I’ve heard it’s better to destroy it within the actor itself.

well there’s a whole lot of stuff going on in my game but I explain some parts.
there’s an actor called item manager that’s responsible for spawning these actors into the world.
there are some actors in my level that the player will interact at some point, and when they interact the actor must destroy another specific actor that was spawned from item manager.

the way I wanted to do this is to get a reference to item manager via an object reference and then get access to those spawned actors, so each actor that was spawned must have their own object reference assigned after they are spawned.

i should mention that i already figured it out on how to get access to item manager I just need a way to get access to spawned items which seems like casting is the only way.

I appreciate that u want full information to help the best u can but this is getting over complicated for a simple question. I have already figured it out all the things that u just mentioned.

the only thing i want is to get an Object reference to the actor that was spawned that’s all. the same way when u right click on the return value and promote it to variable. it’s just that method doesn’t work here bcz the return value is just an actor, and there’re multiple actors being spawned.

and when they interact the actor must
destroy another specific actor that
was spawned from item manager.

How do we know which one is the another specific actor? You keep saying specific but we somehow cannot arrive at what makes it specific.

  • there are 100 actors in the level, spawned dynamically by the manager, very random and we know nothing about them. I’m fine with that.
  • what is the decision making process behind choosing one of them?
  • are you tagging the actors?
  • do they have a special variable?
  • do they have a unique component?
  • is there some way of assignment?
  • are there any criteria?
  • anything unique that separates the desired one from the rest?

I’ve already added the spawned actors to an array I just don’t know how to get them individually.

Drag a wire from the Array and Get. You need to know the index. So we’re now back at the beginning.

You’ll very soon realise why I was asking the questions…

1 Like