I have a strange situation here where Unity usually hangs every second time I start the player from the editor. So, the first time I click Play, it starts normally, the second time I click it, it hangs after a couple of seconds.
This is a pretty heavy-duty project, with a lot of network communication, asset bundle loading, complex game objects are spawning regularly, so it could be anything.
I’ve tried attaching the VS debugger to Unity, but when the hang happens, I never see my code in stack traces, so I presume it always hangs in Unity-specific code, not in C# scripts.
Can you show the stack traces view in VS? Generally, hanging while entering playmode means that Unity is waiting for spawned threads from previous playmode to exit.
Well, thank you for pointing me in the right direction. While capturing the stack traces, I’ve noticed something which led me to actually solve the issue - it was my own fault after all, and one of the threads actually had C# code.
There was a co-routine waiting for a flag set by another co-routine, and it didn’t have a “yield return null” so that made it a potential infinite loop and the source of the hang, depending on which co-routine got scheduled to run first. Apparently it was an accident that in the second run the checking co-routine usually got scheduled before the setting one.
We haven’t noticed it before during development because previously that flag was always set.