I want to get an array of all objects of given class in range R from given point. Specifically Actors in this case, if it’s relevant. What would you recommend as the best way in terms of simplicity and optimisation?
On the forums here I found a recommendation to use ‘Multi Sphere Trace For Objects’ with Start point being the same as End point. But the ObjectTypes param does not have an option for Actors. For the time being I used WorldStatic + PhysicsBody + Pawn and that seems to collect all objects I care for but I’m not sure if I won’t run into some problems down the line if new types of objects are created.
Other solutions I found suggest to get an array of all actors on the level and loop through them checking distance but I expect that to be a very heavy solution for big levels with thousands of objects.
You could use a sphere collision set to overlap all and get all overlapping actors of class. If the sphere is part of the actor, you can add / remove overlapping from array and keep track of those that are still inside.
I think you do not want to get the distance to really every Actor in your Scenes. So… tag the needed Actors…
Take a foreach loop with the returned array and check for VectorDistance between Player and Target Actor.
If Distance is below your specific Range… Add him to an Array you can work with, after completed Loop.
You could use GetAllActorsOfClass, too.
But it would require additional steps if you want to add more actors than just that specific class.