C# GameObjects Instantiate Into Each Other Issue

I have this script that randomly generates prefabs within a 2D box collider. However I’ve noticed that sometimes the prefabs spawn into each other. Is there anyway I could prevent this from occurring? I’m not really sure where to start since all of the gameobjects spawn at the same time.

using UnityEngine;
using System.Collections;

public class GeneratePrefabsWithinCollider : MonoBehaviour {
	public BoxCollider2D playerCollider;
	public GameObject[] placeableObjects;
	public GameObject currentObject;
	public int numberOfObjects;

	public void Start () {
		for(int i = 0; i < numberOfObjects;i++)
		{
			for(int j = 0; j < placeableObjects.Length;j++)
			{
			currentObject = Instantiate(placeableObjects[j],GeneratedPosition(),Quaternion.Euler(0, 0, Random.Range(0f, 360f))) as GameObject;
			currentObject.transform.parent = transform; 
			}
		}
	}
	
	Vector3 GeneratedPosition()
	{
		float x,y;
		x = UnityEngine.Random.Range(transform.position.x, transform.position.x + GetComponent<Collider2D>().bounds.size.x) - GetComponent<Collider2D>().bounds.extents.x;
		y = UnityEngine.Random.Range(transform.position.y, transform.position.y + GetComponent<Collider2D>().bounds.size.y) - GetComponent<Collider2D>().bounds.extents.y;
		return new Vector3(x,y,1);
	}
	
	void OnTriggerEnter2D(Collider2D other) {
		if(other == playerCollider){
			for(int i = 0; i < transform.childCount; i++){
				if(transform.GetChild(i).gameObject.activeSelf == false){
					transform.GetChild(i).gameObject.SetActive(true);
				}
			}
		}
    }
    void OnTriggerExit2D(Collider2D other) {
		if(other == playerCollider){
			for(int i = 0; i < transform.childCount; i++){
				if(transform.GetChild(i).gameObject.activeSelf == true){
					transform.GetChild(i).gameObject.SetActive(false);
				}
			}
		}
    }
}

They’re not instantiated at the same time, they’re instantiated one after another. You can check if an object overlaps any of the created objects, move it to another random position and check again, and repeat until it’s in a good position. If they have colliders you can use physic to check, or you can make a fast check for distance if the objects are similar. This has a problem, if you instantiate too many objects you might get stuck if there’s no valid position, and it’s hard to know when that actually happens.