Hello, I noticed that if all of the Objects in the Pool are active in the hierarchy at once, (before the first enemy has Deactivated itself though death or reaching the end of the path) I get an Index out of Bounds exception, and the spawning cycles breaks.
I have fixed this in my code, by changing the “while(true)” loop to a Boolean “while(spawning)”, that I can toggle with the press of the space bar… this essentially just resets the coroutine so it will begin again. However, I have tried to figure out a solution, or check against going out of bounds, to allow me to keep the while(true) loop going, but I cant figure it out.
If I increase the number of objects in the pool to a higher number (i.e. 11) then the first enemy reaches the end of the path before the last pool enemy spawns, and its not a problem, but this leads to way too many enemies on screen at once.
Is there a way to safely exit the the EnableObjectsInPool loop, if all Object are active in the hierarchy?
Any suggestions?
EDIT: I just realized I can simply increase the delay of the coroutine, to properly time the enemy spawning with fewer enemies… But, my question still stands…