Tower sphere range

I wonder how u guys trace enemies in your games? In most of my examples, I’m just using get actors from class, and then I get distance to my actor and checking is he in range. But what if you got few thousands of actors, and much more enemies ? Then u got like few thousands x several thousands iterations per frame ? Today i found function sphere overlap actors(It looks only in some radius and it have built filter for classes). Is it much more effective than iterating through all actors with class or it is similar implemented?

I’d recommend looking into collisions, specifically Overlapping. You can use Begin overlap to get any enemies from a sphere component and save them in a TArray, and End overlap to remove them. This way it will be event based and you wont have to iterate through all existing actors, and any time you want you have an array with all the enemies in range.

Tell me if I understood u well. U re sugesting to make in component tab, as a root invisible sphere, on this static mesh(which would be defence tower etc.). So player would be overlaping this invisible sphere and this sphere should have radius equal to tower range ? It is very nice idea, but I supose overlaps events are implemented based on iterating through all actors aswell ? On second hand this iterations are built so I can’t avoid them, then my code is just second implementation of iteration through all actors(so it is better solution). So the question is if I dont use overlap events on graph does engine generating thoose overlaps anyways ? If I could disable overlaps events and atleast call my function each 1 second instead of per frame overlap isnt’ it worth the effort ?

I don’t think you need to worry about that. Unreal handles collision in a smarter and more efficient way. Try it out :slight_smile: