Get all actors in distance ...?

Hello there,

Is it possible to get an array / list of all actors within a specified distance from the pawn using blueprints?

Let’s say when an event triggers I have to destroy ALL actors (static meshes, lights, particle effects etc.) that are 10.000 units around the pawn. How about doing that?

Thanks for reading!

#For Each Loop

Use the ForEach Loop!

Specify AActor as the class

and then do a distance check, comparing each actor to your source actor / player unit.

:slight_smile:

Rama

Hey Cence,

For a blueprint, you can use the Get All Actors of Class node to get all actors of a particular class (including just Actor) and then use that Array with a ForEachLoop as Rama mentions. In the loop, you can use the following setup to do a distance comparison and then execute whatever additional code you want after the Branch:

Hope this gets you going in the right direction!

1 Like

Exactly what I was looking for!

@Steve Allison
Isn’t there something nicer in UE4 ?
I mean a native function that can query a scene graph and make it faster ?

Hi,

The easiest way to do this is using a MultiSphereTrace. Put the player location in start & end and then add a radius.

Hope this helps.

2 Likes

Straightforward. Love It!

Instead of tracing, or a foor loop for all actors of class…

A proper (best practice) would be to add a gameplay tag to the actors when they spawn in, then loop the actors with that game-play tag to check a distance.

Tags are accessible via the string array variable Tags.
Though, you may need to edit the actor’s class in CPP to make the variable available, this I do not recall…

The loop should be less expensive than a multi trace - when dealing with high number of actors/items that react to the trace.

1 Like