How to stop Instantiate from spawning duplicate prefabs

Hello! I am having trouble making my script work in a way that is stops the instantiate request from spawning duplicate prefabs. I just want to check if a particular prefab is already present and if it is, stop the instantiate request from trying to load it again. That way only one prefab type is present and others can be loaded. Is there something I am missing?

public Transform moveSpot;
private float minX;
private float maxX;
private float minY;
private float maxY;
public GameObject ItemPrefab;
public GameObject ItemPrefab2;
public GameObject ItemPrefab3;
List<GameObject> prefabList = new List<GameObject>();
private float speed;
private float waitTime;
private float startWaitTime;
private float SpawnTime;
private float startSpawnTime;

void Start()
{
    // The start of the script.
    speed = 1f;
    startWaitTime = 3f;
    waitTime = startWaitTime;
    minX = -1.6f;
    maxX = 1.6f;
    minY = -4f;
    maxY = 4f;

    startSpawnTime = 3f;
    // This is what you use to spawn items ---- You may need to delete.
    SpawnTime = startSpawnTime;
    // This is what you use to spawn items ---- You may need to delete.
    moveSpot.position = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
    // Basically, the starting location is randomized based on the x and y ranges you specify.

}
void Update()
{

    transform.position = Vector2.MoveTowards(transform.position, moveSpot.position, speed * Time.deltaTime);
    // Basically, the updating location is randomized based on the x and y ranges you specify and the speed you specified it to move.

    if (Vector2.Distance(transform.position, moveSpot.position) < 0.2f)
    {
        // Basically, it wants to make sure the moving items is close to the updated MoveSpot position.
        if (waitTime <= 0)
        {
            moveSpot.position = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
            waitTime = startWaitTime;
            // Basically, if the time to move is less than 0, the MoveSpot will move to a new location and start the countdown all over again.
        }
        else
        {
            waitTime -= Time.deltaTime;
            // Otherwise, the item to be move will remain in place until it is time to move.
        }

        if (SpawnTime <= 0)
        {
            prefabList.Add(ItemPrefab);
            prefabList.Add(ItemPrefab2);
            prefabList.Add(ItemPrefab3);

            int prefabIndex = UnityEngine.Random.Range(0, 3);
            Instantiate(prefabList[prefabIndex]);
            
            SpawnTime = startSpawnTime;
            // This is what you use to spawn items ---- You may need to delete.
        }

        else
        {
            SpawnTime -= Time.deltaTime;
        }
    }
   
}

}

Why don’t you just remove the prefab from the list once you have instantiated it?

prefabList.removeAt(prefabIndex);

and once the list is empty you can stop the loop
you will need to add items to the prefabs list at start though

@BeauWares You can attach this script to make the prefab a singleton. This doesn’t prevent the game from trying to spawn multiple copies of the prefab, but it does destroy any duplicates which are created.

https://gamedev.stackexchange.com/a/116019

public class Singleton : MonoBehaviour
{ 
    private static Singleton _instance;

    public static Singleton Instance 
    { 
        get { return _instance; } 
    } 

    private void Awake() 
    { 
        if (_instance != null && _instance != this) 
        { 
            Destroy(this.gameObject);
            return;
        }

        _instance = this;
        DontDestroyOnLoad(this.gameObject);
    } 
}

Just replace Singleton with the name of your class or prefab.

The line “DontDestroyOnLoad(this.gameObject);” is optional but can be added if you want this prefab to persist across scene changes.