Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Resolved Editor freezes when debugging inside a loop

Discussion in 'Editor & General Support' started by Mnooper, Jan 17, 2023.

  1. Mnooper

    Mnooper

    Joined:
    Aug 11, 2022
    Posts:
    1
    Currently writing a startup script that makes use of quite a few loops, and am in the process of debugging.
    I create a breakpoint inside the loops, attatch Visual Studio, enter play mode and start debugging.
    My problem is when inside any of the loops, the unity editor is completely frozen and unresponsive, both while the code is running and im stopped at a breakpoint. I can't interact with the window at all, including unpausing/stopping the program from the editor.
    When I stop the program from VS, unity still doesnt respond, and I have to close it through task manager and reboot if I want to continue.
    (I understand why unity would hang like this while in a loop for some time/infinitely, but not at any other time)
    Is there any way around this?
     
    Last edited: Feb 6, 2023
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    725
    It's a bit inevitable! You're debugging the editor process, so everything's going to be frozen once you hit a breakpoint.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,936
    This is because the main Unity thread being also the main editor thread.

    The main limitation is you can't debug stuff that is being constantly run, eg, updated every frame.

    You can put breakpoints in the interesting bits as long as they're guarded so you do not hit the breakpoint until you navigate to exactly the state you want to debug.

    Once you've finished breakpointing / inspecting, just hit run again in the debugger.