Hello, i have 200 to 300 enemies (all with the same parent class) on stage and i would like to get reference ro them all periodically to check the closest one and do other stuff
I made an array of this actors pointers that geta updated every time an enemy is spawned or destroyed. Now looping through this array causes after some time a crash with no specific error.
I thought to get them using get all actors of class or sweep multi with a long range. Is it a good idea or do i have to struggle and try to find a way to make the array work or is there another way ?
Get all actors is not gonna be great with that many.
Something you could do, is have a central data area ( could be the game instance, or an actor BP in the level ), and when an enemy is spawned, they register themselves with it. When an enemy is destroyed, they remove themselves.
Also, rather than running through them every tick, or few seconds, you could get them to report when then are near.
I realize this could mean they’re all checking their distance on tick, but you could have a more elaborate algorithm. For instance, an enemy can check its distance, and decide not to monitor for a while, if they are nowhere near.
And so on…
You can also just have a big fat collison sphere around the area of interest. Then you by overlap when things are going on.
You can also just have a big fat collison sphere around the area of interest. Then you by overlap when things are going on.
this looks like the solution of sweeping every half second and see what is in the sphere, is tha it? that could be pretty simple if is not bad for performance