Help in array

Hey,

I’m trying to get all actors from class, and then check the distance to the player, if the player is in distance, trigger several events, however, it seems that the events would happen to different actors and not to the same one, how would I tell the BP to talk to the specific result based on the distance check? Am I doing something wrong? Any better way of doing this?

I hope the image helps, thanks in advance.

This is one way of doing things, but it may end up being very inefficient in the end.

If these actors will only interact with your player based on distance, it would make more sense to have your player be responsible for finding these other actors instead.

How I would do it, I’d make a sphere collider around my player and on overlap I’d cast the other actor to the Light class and on successful cast, execute that code.

This way you don’t have every Light actor looking for your player, you just have your player looking for the Light actors within the group of actors that overlap with your sphere collider.

If you’d like to check on a bespoke basis instead of when something is overlapped, you can just check which actors are currently overlapping the sphere in a custom event. You can even filter in only the specific class you want and run a for loop on them!