Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Unity freezes on Debugging with Visual Studio

Discussion in 'Code Editors & IDEs' started by ftejada, Feb 23, 2022.

  1. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi everyone!!!!

    I need help to solve this problem:

    I have a project that was running fine so far, but since 3 days ago, every time I hit the button in Visual Studio to debug my code, Unity freezes and doesn't respond. It only happens to me with this project.
    Sometimes this windows appears and it takes forever to wait... or at least until I get bored and desperate and stop debugging in VS. But I have waited more than an hour on one occasion to try...

    TickGlobalCallbacks.jpg

    TooltipTick.jpg

    I have searched on google but I have not found anything that helps me to solve it and I have been 3 days without being able to work, wasting all the time trying to debug my code, but without success.

    I have tried different versions of Unity 2020.3.x, 2021.x, etc but still the same.
    I have also installed VisualStudio 2022, but the problem is not solved either.
    I have tried deleting the "Library" folder from the project so that Unity would regenerate it again. But it hasn't solved the problem either.
    I don't know what else to do or how to fix it.

    Can anybody help me?

    Greetings and thanks in advance
     
    Last edited: Feb 23, 2022
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,163
    If you just run your game in play mode in Unity, does it run correctly? That is, don't use the VS debugger.
     
  3. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Yes. works fine without doing VS Debugging
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,163
    If you're using source control, you could try rolling back.
    Another possible option is try deleting the solution files and letting Unity regenerate them.
    Also make sure that VS is listed under preferences as your external editor.

    But, if you aren't using any source control, make sure you either do so or do some sort of backup before trying anything.
    If the debugger worked fine before and now doesn't and it works fine in other projects, you'll need to see what you changed 3 days ago.
     
    ftejada likes this.
  5. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi again and thanks for the help!
    I've deleted the VS solution files and reopened the project to have it build them again.

    But the problem has not been solved.
    Any other ideas or tips?

    Another thing I've noticed is that when I get Unity to unlock by waiting many minutes since I turned on debugging in VS, every time I add or remove a breakpoint in VS, Unity freezes again for about 40-50 seconds. Even if I add or remove breakpoints without play mode.
     
    Last edited: Mar 2, 2022
  6. Alex-Thibodeau

    Alex-Thibodeau

    Unity Technologies

    Joined:
    Apr 18, 2013
    Posts:
    27
    Just to confirm this is the editor that you are attaching the debugger to? Does the debugger attach successfully and you can pause execution to inspect callstacks and whatnot? You might be able to figure out where things are stalled by doing this. As others have mentioned if this just started in the past few days with only code changes to the project it would indicate that there may be some thread that is failing to end on domain reload causing the hang.
     
    ftejada likes this.
  7. PanicEnsues

    PanicEnsues

    Joined:
    Jul 17, 2014
    Posts:
    187
    Sometimes I'll get that and have to "Delete All Breakpoints" in VS before it will run Attached.
     
    ftejada likes this.
  8. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Yes.
     
  9. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    @Alex-Thibodeau For some unknown reason yesterday and today I have been working on the project and it seems that everything has worked noticeably better. The problem has not been so serious and in a matter of 1~2 minutes Unity was unlocked and could do the debugging.

    Perhaps the improvement was when I restarted the PC after Unity regenerated the VS solution that I deleted.

    I'll keep watching...
     
  10. Alex-Thibodeau

    Alex-Thibodeau

    Unity Technologies

    Joined:
    Apr 18, 2013
    Posts:
    27
    As someone else has mentioned if you have a lot of existing breakpoints it can cause behavior like this as well. The the debugger has to jit and then resolve all of them which can be slow.
     
    ftejada likes this.
  11. sprakash99

    sprakash99

    Joined:
    Mar 24, 2021
    Posts:
    2
    A bit late, but I hope this helps:

    For me, the issue was that the unity services core module was updated in my last commit, from 1.4.2 to 1.4.3.

    The text below is from Packages/packages-lock.json
    Code (CSharp):
    1. "com.unity.services.core": {
    2.       "version": "1.4.3",
    To fix it, I closed vs and unity, deleted all the .csproj files, .sln files, and the .vs folder in my project and re-opened Unity. Once these were regenerated, I could use the vs debugger again.

    I was following this Microsoft docs page on troubleshooting.
     
    nirvanajie and ftejada like this.
  12. EversorDvL

    EversorDvL

    Joined:
    Sep 26, 2015
    Posts:
    8
    Same happened here, i only had like 2 breakpoints, but when i deleted them the issue was fixed. There is prolly a bug in the parsing of breakpoints that hangs the editor forever. Keep in mind that restarting windows or power cycling it did not solve the issue.
     
  13. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,847
    But you are aware that when your game executes and the debugger actually hits a breakpoint or you press pause inside VS, the Unity editor is expected to not respond. Unity runs in the main thread when running in the editor. So when the debugger halts the main thread in order to debug it, the Unity editor application can not respond anymore until you resume execution. Of course break points can immediately break the execution again.
     
  14. EversorDvL

    EversorDvL

    Joined:
    Sep 26, 2015
    Posts:
    8
    Yes but the breakpoints weren't hit, and execution wasn't stopped by VS (at least not i a way I could control it). I use VS and c# since 2005 across all platforms so i'm pretty keen on the basics.
     
  15. Loden_Heathen

    Loden_Heathen

    Joined:
    Sep 1, 2012
    Posts:
    480
    This has been an on again again issue for years with Unity but it does seem much worse with more recent updates.

    For note if your are patient it will eventually catch up and move on but ya its not a good work experience not even a little

    Visual Studio debugging was the best way to debug Unity projects but its just gotten really clunky and error prone
     
    christh likes this.
  16. Huxii

    Huxii

    Joined:
    Sep 15, 2018
    Posts:
    36
    Same issue for me with Unity 2021.1.21f1 and VS. I am having just one breakpoint and this isn't hit, unity just freezes. Sometimes I don't even get the loading bar, but after reading the tips here I waited 1 minute after starting the game, then eventually the breakpoint is hit, and I can debug. Several days ago it happened just sometimes, now it's happening every time. Btw., I can't even press PrtScn (print Screen) on the keyboard, It wont work either.
     
    Last edited: Dec 29, 2023
  17. KaiMiraGames

    KaiMiraGames

    Joined:
    Jan 2, 2020
    Posts:
    17
    Just resolved this issue myself, and it was because of a conflicting breakpoint and watch expression - the watch expression would have hit the breakpoint, and unity hit the breakpoint, leading to a deadlock. Clearing all the watch expressions resolved the issue for me.