Assigning actors to Arrays based on distance to Player

I’m kinda new to Arrays and blueprints in general… I have multiple EnemyAI actors in my level and I want only the actor that is within a certain distance from the player to be assigned to a new array. When the player is outside that proximity, the enemy actor is removed from the array.

Basically I’m trying to make a smart system to dynamically switch out actors so I can use their location in the material editor to drive a sphere mask. But just for a max of 2 actors in the array. I’ve tried a few things but cannot find a way to determine the actual index of the actor in range.

You could have a looping function that repeats every ~0.3 sec inside of your player.

The function will gather all enemies in the level into a total enemy array. Then you can loop through that array (for each) and add them to a different array, e.g 'EnemysInProximity". You’ll need to clear that array each time you loop through the total enemy array to find close enemies (simplest solution to re checking and adding enemies). You could do an additional check to make sure that the length of the enemies in proximity array is not longer then 2 - if its equal to 2, dont add any more enemies to the array.

You can then use the EnemysInProximity array to get references to those enemies, and any related information. You’ll want to make your system as modular as possibly - whatever you’re trying to do with a sphere mask should be a function or event inside of your enemy which you can call from the reference you get from the proximity array.

I hope this helps.

I was trying a lot with loops and stuff in Blueprints, but Everynone suggested a much more simpler approach to it. Works exactly like I wanted

Yeah, using a sphere works well too. You’ll still need to end up looping through the array to activate whatever functions you need. I definitely recommend setting up separate collision channels for this, it’ll save you in the long run if you end up doing other things from your player like raytraces.

Yeah i set up custom collision channels for this. I’m wondering if anyone has managed to get loops working in the material editor.