Getting actors within x distance?

Hey guys, so I want to be able to detect actors within x distance and I know there are many ways to go about this. Basically it’ll be used for my AI to detect nearby bots and dynamically form groups, so they can communicate faster with each other.

One way to do this, is to loop through all actors in the world and check the distance, can be quite fast but costly.

The way I would like to do this, is by creating a volume, then using GetOverlappingActors() then destroy it.

How would I go about this effectively?

Have a SphereComponent and you can have its collision properties only overlap with the same ObjectType as itself, presuming the other actors have the same SphereComponent. Then whenever you want to check who is within the x distance, the x radius, you can call GetOverlappingActors() for the component. Overlap detection for two sphere’s is pretty cheap, and you’d be taking advantage of whatever collision filtering mechanisms UE4 has.

Perfect thanks a lot. I can’t wait to make good use of this. I plan on my dynamic AI tactics based on the bots in the group. So they change how they fight and their formation and flanking etc…