Hey, I’m trying to populate a square area with different objects using random (X,Y) locations. What is the best way to prevent them from overlapping each other? There will be a lot of them, so I’m trying to find a reasonably performant solution. My first idea:
Every object has a small set of Sphere Colliders that are set to overlap only with their special ‘spawnBlocker’ object type (for performance). You can place & scale them in object’s BP to approximately match any object shape:
After getting random X,Y location, objects could check if their sphere colliders overlap any other colliders from other actors (e.g. by SphereCollisionComponent.GetOverlappingComponents() → if ( InOverlappingComponents].Length > 0 ) )…
If not, they can spawn there, if yes, they they must select a different random (X,Y) location and check again.
This could work, but I have a feeling that there is a better way to achieve something like that. I would be grateful for some hints… Any ideas?