Null Reference Exception error from WaitForSeconds

When I have yield WaitForSeconds(0.3); in my code, everything works just fine. When I remove that line (and nothing else is changed), it returns NullReferenceException, and everything breaks. Also, it will only wait for 0.3 seconds. If I change it to 0.1 seconds, it gives me the same error. As far as I know, it only waits for 1 or 0.3 seconds. I’ve read about the NullReferenceException error, and basically what it means is that a variable is trying to refer to a null value. It doesn’t make sense to me why deleting yield WaitForSeconds(0.3); would return a NullReferenceException. Here’s the part of my code:

Working:

for (var s : int = 1; s <= mapLength; s++) {
    yield WaitForSeconds(0.3);
    ngb++;
    
    ...
}

Broken:

for (var s : int = 1; s <= mapLength; s++) {
    
    ngb++;
    
    ...
}

I’d prefer to have the WaitForSeconds gone. Please help!

You didnt really paste any code. But only possible reason i can think of is, that in that 0.3 seconds (or more) that you are waiting, one of the variables you use that is initially unassigned gets assigned somewhere.