2D instantiate difficulty

Hi fellow
I have a little problem with my code.
I’m developing a 2d game, and i have a dificulty with my instantiate.
In my game, the sphere prefab is instantiated randomly in a region. It is sphere grows over time, and another sphere arises.
My problem is that I added a distance to be instantiated, but I noticed that sometimes spawns one sphere over another.
How can i fix this?
(PS:
I’m not very good with codes)
Thanks :slight_smile:

Before you instantiate, find a proper position to spawn. You can generate a random spot, and (assuming your spheres have 2D colliders) use Physics2D.OverlapPoint or Physics2D.OverlapCircle using the size of the sphere prefab, to check if the random location is already occupied by another sphere. If not, generate a new position and try again. Once you have a position that doesn’t overlap other colliders, you can spawn your new sphere there.

I’ll try this, thank you :slight_smile: