coroutine infinite loop ( i think )

When i try to call this coroutine, unity frozen and i suspect ive made an infinite loop somehow but idk whats wrong

IEnumerator StartSpawning ()
    {
        isSpawning = true;
        for (int i = 0; i < numOfObjToSpawn; i++)
        {
            SpawnOnCircle(objToSpawn, spawnRange);
            yield return new WaitForSeconds(spawnDelay);
        }
        yield return new WaitForSeconds(waveDelay);
        numOfObjToSpawn++;
        isSpawning = false;
    }

here’s whats calling it

private void Update ()
    {
        if (Input.GetKeyDown(KeyCode.Return))
            gameStart = true;
        while (gameStart)
        {
            SpawnController();
        }
    }

    void SpawnController ()
    {
        if(!isSpawning)
            StartCoroutine(StartSpawning());
       
    }

Your infinite loop is the while loop in Update. I don’t see where gameStart ever gets set false in that frame, so that while loop will never end.

1 Like

omg such a novice mistake facepalm ive been having these for quite a while now T_T
thx for ur help :slight_smile:

1 Like

It happens :slight_smile:

Sometimes when you hit an issue you’re having trouble seeing, you just need to step away for a bit or have someone else take a look.