Enemies not set back to zero when restarting too quickly

Hi,

I have 2 coroutines that run to spawn enemies and powerups. When my player dies, I have a title page that displays and asks the user to press enter to restart.

What I have seen is that if I press Enter too quickly after the game ends, it restarts with enemies and powerups spawning twice as fast.

I use StopAllCoroutines() when the player dies, but I wonder if it doesn’t have time to fully execute before I start again and this could be the issue?

I would like to know if this is a common thing or I am doing something wrong? If this is common, how do you get around it? Is there a way to instantly stop coroutines? Is there a way to delay showing the title screen until coroutines have stopped? Something else?

Thank you very much,

John

The best way to get around this is to just reload the scene and start the level afresh.

If you cannot do that, then put some debugging in and ascertain first if the old coroutines running really are the issue, because it could be that you’re simply relaunching the coroutine twice the next time, for any number of reasons.

Hi,

Thank you for your reply, I will try that out and let you know how it goes. I never thought about reloading the scene, so will figure out how to do that.

Thanks,

John