Search Unity

Unity Freeze when connecting VS Debugger

Discussion in 'Editor & General Support' started by Joe_86, May 4, 2018.

  1. Joe_86

    Joe_86

    Joined:
    Jan 12, 2015
    Posts:
    6
    Hey Guys.

    Since three days, i have a really annoying issue:
    When i connect the Visual Studio 2017 Debugger to my Unity Installation (Unity 4.x), the Editor freezes completely. There is no error message, timeout or anything else. If i disconnect the Debugger, Unity continue like nothing has happened. I have not to be in play mode to freeze the Editor with the debugger.

    This Bug is Project independent. I have the same problem with a completely new and empty Project. There is no difference if i use the Visual Studio for Unity Plugin or not.

    I use the latest Version of Windows 10 + Visual Studio 2017 Professional.

    I already tried to completely uninstall Visual Studio 2017, Unity and even the last Windows 10 Updates, but nothing seems to work.

    If i connect with MonoDevelop, everything works fine, but MonoDevelop is no alternative in my Company.

    Do you have any ideas or tips what else i can try to fix this?

    Thx!
     
  2. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    318
    Ran into the same issue today (though on 2017.3.1, win 10, vs 2017). For whatever reason, if I click the "play" button that says "Attach to Unity", Unity simply locks up until I detach. I am able to debug just fine though if I go to the "Debug" menu and choose "Attach Unity Debugger". Hope that helps someone.

    EDIT: Nevermind. The problem is now presenting itself even when attaching through the menu... It worked for about 20 minutes.

    Edit again: The problem ended up being conditional breakpoints. If I have a conditional breakpoint in the project, it locks up Unity (even though it isn't hitting). The breakpoint will hit one time, and after that, nothing works. Restarted Unity, Visual Studio, even a reboot didn't get the breakpoint to work again. Removing the breakpoint resolves the issue.
     
    Last edited: May 30, 2018
  3. Joe_86

    Joe_86

    Joined:
    Jan 12, 2015
    Posts:
    6
    @gtzpower: Thx for the feedback. Unfortunately, i have still this issue without any breakpoints.
     
    RiverExplorer likes this.
  4. Lardalot

    Lardalot

    Joined:
    Jun 19, 2013
    Posts:
    10

    Thanks!! I haven't been able to debug properly for for days, I just deleted all breakpoints and now it's all good again.
     
  5. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    996
    Still happens~
     
    sirshelley likes this.
  6. KBVDev

    KBVDev

    Joined:
    Dec 1, 2017
    Posts:
    2
    Had the same issue just now. Deleting breakpoints fixed it for me, but this bug still needs to be adressed.
    Has someone found a bug report?
     
  7. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    318
    I've just started hitting this as well, pretty big deal not being able to debug code efficiently.

    Debug works the first time in a session (clean boot), after that it just locks up every time.

    // WildStyle
     
    RiverExplorer and creepteks like this.
  8. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    644
    I thought I was the only one having these issues, since we use a hot-reloading external DLL setup, I figured it must be all the crazy things we're doing the debugger just poops itself. It worked pretty alright with Unity 2017 3.1p1 and VS2015 (can't recall which VSTU version). But then as soon as we updated to latest VS2017 (15.8.4) and Unity 2018 2.6f1. The debugger freezes every single time I detach it, almost a 100% repro. I thought it must be Unity 2018, so we went back to Unity 2017 4.1f1, while it happens _slightly_ less, it still happens quite a lot, very frequent.

    Every new Unity comes in, you get all these new fancy features yet the core programming environment is not robust. We're considering all sorts of work-arounds atm, even developing our game in a separate exe, and abstracting out the rendering part, just so we could debug... Not cool, not cool.
     
  9. Hullabu

    Hullabu

    Joined:
    Oct 23, 2014
    Posts:
    18
    Same freezes.
    Tested on:
    Unity v2018.2.7f1 and Unity v2018.2.8f1, VS2015 and VS2017
    Nothing helps. Impossible to work.
     
    eduardovmendes and gdarie like this.
  10. Froghuto

    Froghuto

    Joined:
    Oct 4, 2012
    Posts:
    61
    Had the same problem, deleting all breakpoints fixed it for me too
     
  11. Michieal

    Michieal

    Joined:
    Jul 7, 2013
    Posts:
    92
    gee... this is fun!
    Mine was working just great until I updated visual studio. Now, it takes 5 minutes (during which both VS and the Unity Editor are frozen) to start. And, heavens help you if f-10 into something like Unity Analytics... It just hangs.

    Win10
    Unity 2018.2.8
    VS2017 15.8.28010.2026
     
  12. Cross22

    Cross22

    Joined:
    Sep 26, 2014
    Posts:
    22
    Using Visual Studio 2017 for Mac it doesn't freeze - instead it crashes the Unity process..
     
  13. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    Happens with Unity 2018.2.7f1 and VS 2017 15.8.4 on Win 10. Mine also only started after I updated VS. Originally after the update, it would only fail 1/3 times, but now it fails 100% of the time.
     
  14. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    318
    There has been an update to Visual Studio and the Unity tools bundled with it, evidently this fixes the issue, although I've not had time to confirm yet.
     
  15. KISP

    KISP

    Joined:
    Sep 13, 2018
    Posts:
    32
    I've updated to the newest patch, and everything seems to be working again.
     
  16. WildStyle69

    WildStyle69

    Joined:
    Jul 20, 2016
    Posts:
    318
    Right - takes a while to attach for me, however does seem to work now which is a relief!

    // WildStyle
     
  17. gdarie

    gdarie

    Joined:
    Jun 3, 2018
    Posts:
    5
    I have the same issue with unity and vs2017. it keeps hanging and is frustrating that you cannot do debug.
     
  18. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    for me it's frozen without any breakpoint or attaching debugger. Just clicking Open C# Project from the Project window will open vs and it'll stay this way for hours. Tried system restore, updated VS 2017 community to the latest version and finally reinstalled Windows (Thinking there's a virus causing this- Was recently effected with Neshta C Virus) all in vain. The same thing is happening.
    Project isn't opening from Unity.
    Visual studio loads fine when open standalone.
    and if Unity Project is opened from the recent solution list, it hangs there as well.
     
  19. DerWoDaSo

    DerWoDaSo

    Joined:
    May 25, 2009
    Posts:
    131
    Clearing all breakpoints via menu (Debug > Delete All Breakpoints) solved the issue for me!
     
  20. mbrindic

    mbrindic

    Joined:
    Mar 13, 2014
    Posts:
    16
    Oh thanks man, you're a lifesaver!
     
    KwahuNashoba and MrLucid72 like this.
  21. northernthumb

    northernthumb

    Joined:
    Jan 2, 2013
    Posts:
    6
    After going down an FMOD blind alley, this worked for me too.
     
  22. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    996
    This issue is at the top of Google and still happens, today, in Unity 2018.3
     
    midnightcrawler1 likes this.
  23. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    616
    Yep, this is happening to me right now in 2018.3.6f1
     
  24. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    Same here.
    Deleting just the breakpoints didn't help.
    Also removed project and solution file ( these are generated by Unity in the root of the project and have the extensions *.csproj and *.sln) and restarted Unity/VSC
    That worked for me.
     
  25. Num0n1

    Num0n1

    Joined:
    Aug 19, 2016
    Posts:
    8
    deleting all the breakpoints worked for me ,thanks guys.
     
  26. rwgames68

    rwgames68

    Joined:
    Jul 2, 2012
    Posts:
    7
    Deleting all breakpoints worked for me as well, thanks.
     
  27. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Also, can be done via the "Breakpoints" window. In my case it showed a list of several hundred of obsolete breakpoints, even from files that actually no longer existed. That really surprised me. They accumulated there over several months.

    In this window, select the entire range of those breakpoints (by holding shift-key), and delete all of them.
     
    francoislaura10 likes this.
  28. albertoha94

    albertoha94

    Joined:
    Apr 14, 2015
    Posts:
    2
    Just as a Note.
    This is still hapenning in Unity 2018.3.13f1.
    Man this is annoying.
     
  29. julienkay

    julienkay

    Joined:
    Nov 12, 2013
    Posts:
    171
    I have an issue that is similar or even the same. I'm on Windows 8.1, Unity 2018.3.10f1, Visual Studio 2017 (15.9.12), VSTU 3.9.0.3
    Unity runs fine when there are no breakpoints. As soon as I add a breakpoint that should be hit, Unity freezes (which is kinda expected behaviour when hitting a breakpoint), but in Visual Studio the breakpoint is not hit. Clicking anything in Visual Studio results in VS freezing too, until I force quit Unity via the Task Manager.

    A thing I noticed is, that VS correctly stops at breakpoints in the first frame of the application. The issue only appears when I click continue or add a breakpoint after the application is already running.

    Another weird thing is, that I'm not able to reproduce this in an empty project. Other people running the same project can use the debugger just fine.

    Edit: Another issue that seems related: Whenever I'm in play mode and make changes to a script, once I hit save, Unity freezes completely and I have to force quit.
     
    Last edited: May 31, 2019
  30. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    Connecting to Unity can take up to a minute where there's long periods of freezing.
     
  31. julienkay

    julienkay

    Joined:
    Nov 12, 2013
    Posts:
    171
    Just as an update from my side in case anyone has the same issue:
    I solved this by adding Unity to the excluded processes in Windows Defender.
     
  32. midnightcrawler1

    midnightcrawler1

    Joined:
    Jan 17, 2017
    Posts:
    15
    What's the point of debugging if there are no breakpoints, so disappointing they need to fix this.
     
    eduardovmendes likes this.
  33. UnetDev

    UnetDev

    Joined:
    Aug 28, 2017
    Posts:
    54
    Unity 2019.1.6f1, VS 2019 (16.1.3) and this is still happends.....
    I think the Unitecs should still pay attention to this problem since this topic is already 1 year old and the problem is still not resolved.
    This problem takes a lot of time during development!
     
    ArsenGamedev likes this.
  34. UnrealTati

    UnrealTati

    Joined:
    Aug 18, 2017
    Posts:
    5
    Was having the same issue. Realized I was implementing Async through Task.Run(System.Action). Made a function to handle when I am doing async on a mac.

    if(platform == osx){
    job(); // not async;
    } else {
    Task.Run(job);
    }

    Damn. I really wish Unity would support real multi threading.... not just job sys which won't play well with refs...
     
  35. Rofar34

    Rofar34

    Joined:
    Sep 30, 2018
    Posts:
    4
    You can still set breakpoints and debug. I was having this problem (VS2017) and found this thread to help. When I deleted all breakpoints, I was able to set new breakpoints and it works fine. There must have been some invalid breakpoints set which can happen in visual studio if you have breakpoints and then the code gets modified outside of visual studio and the breakpoint line numbers now point to invalid lines.
     
    twobob likes this.
  36. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    No it didn't (at least not finally)

    What worked just now is removing the VSCode Unity extension completely and re-installing it.
     
    twobob likes this.
  37. Stephen1701

    Stephen1701

    Joined:
    Mar 29, 2016
    Posts:
    132
    Thank you for this!! Once I removed breakpoints it all worked again. Much appreciated.
    It has worked and not worked often and I never noticed it was breakpoints causing it.
     
  38. Suduckgames

    Suduckgames

    Joined:
    Nov 28, 2016
    Posts:
    218
    Having the same problem in Unity 2019.2.13f1 and Visual studio 2019 16.3.10, If I wait long enough the debugger connects in the end. However, if I delete all the breakpoints it works as expected, when the debugger has connected, you can debug normally, however is a pain to delete all the breakpoints every time I want to debug
     
    andyMTSG likes this.
  39. alex_roboto

    alex_roboto

    Joined:
    Nov 11, 2019
    Posts:
    26
    This worked for me too. I can now connect the debugger and Unity is immediately responsive.

    Search for "Windows Security" in "Type here to search" in Windows Explorer Search bar.
    Click "Virus and threat protection".
    Click "Manage settings".
    Click "Add or remove exclusions."
    Click "Add exclusion."
    Choose "Process".
    Type "Unity Editor" in the popup.
    Click OK.

    Thanks for your help @Julien_
     
  40. Laurent_Giroud_Nvizzio

    Laurent_Giroud_Nvizzio

    Joined:
    Mar 18, 2019
    Posts:
    4
    This is apparently not a cure-all solution. I have been having long freezes (large number of breakpoints as usual) and adding "Unity Editor" to the list of excluded process did not help a single bit.

    I assume the fact it solve the issue for you is just pure luck, you probably also cleared your breakpoints (which gets rid of the issue 95% of the time).
     
    dog_funtom likes this.
  41. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Clearing breakpoints just worked for me. Anyone official from Unity care to comment?
     
  42. Fragsteel

    Fragsteel

    Joined:
    Nov 8, 2016
    Posts:
    6
    For me, it seemed to happen if I put a breakpoint on code that would likely get removed by the compiler. Sometimes I'd want to check the value of something right after a line of code executed, so I'd write something useless right after it like

    Code (CSharp):
    1. int x = 0;
    And put the breakpoint on that. This would cause the freeze. Removing the breakpoint fixed the freeze. So I suspect that code doesn't actually exist in the compiled version that's being run, causing the lock-up.

    That may explain why some people are having issues with conditional code - perhaps if the compiler determined that only one of the conditions could ever be met, it compiles out the conditional, and the breakpoint is on non-existent code.

    Again, this is all conjecture.

    EDIT: I tested the conditional theory and it seems unrelated. I tried this:

    Code (CSharp):
    1. if (false)
    2. {
    3.     Debug.Log("IMPOSSIBLE"); //<--Breakpoint goes here
    4. }
    And it did not freeze Unity. Oh well.
     
  43. haxxed

    haxxed

    Joined:
    Feb 17, 2017
    Posts:
    6
    Selecting "Attach to Unity and Play" from VS2019 debugger list worked for me!
     
    EinTheFrog likes this.
  44. alex_roboto

    alex_roboto

    Joined:
    Nov 11, 2019
    Posts:
    26
    This solution solved the problem for me and five other coworkers in my company. Thus, I would not say that the solution is "pure luck" rather it appears that our setups are different and you are encountering a different problem than us. My co-workers all run similar laptops and have similar setups, so it makes sense that one solution would work for all of us.

    I'm sorry it didn't work for you and I know the problem is very frustrating but given a small but still meaningful sample size and success (the commenter who originally posted this solution also had success), I would not discount the entire solution as merely being "luck" or coincidence. It is just not the problem/solution for every setup.

    I have been running this solution for nearly three months now and attach to debug still only takes about 10 seconds the first time (and is faster subsequent times) regardless of how many break points I have set, even ones from previous debug sessions. It previously would take minutes to attach.
     
    Last edited: May 7, 2020
  45. KotoGames

    KotoGames

    Joined:
    Nov 16, 2015
    Posts:
    4
    Indeed it works, but this is not enough.
     
  46. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    315
    This also happens occasionally for me. If I have too many breakpoints, somewhere between 4-6, the Unity editor will just freeze when I start debugging. Stopping debugging will release the freeze, and starting debugging will freeze again.

    Using Visual Studio Community 2017 and Unity 2019.3.15f1

    I don't understand how after two years since this post was written such a basic and fundamental issue still persists.
     
    dog_funtom and hurleybird like this.
  47. hurleybird

    hurleybird

    Joined:
    Mar 4, 2013
    Posts:
    258
    This happens to me all the time. Sometimes Unity won't even unfreeze after exiting the debugger. Happens in VS and Rider. It's so incredibly annoying and wastes so much time!
     
    dog_funtom likes this.
  48. Masivemono

    Masivemono

    Joined:
    Dec 5, 2017
    Posts:
    7
    Happens to me too
     
    dog_funtom likes this.
  49. ma2doctor

    ma2doctor

    Joined:
    Jul 27, 2020
    Posts:
    1
    Since this issue is still around in 2020 (duh!) let me share my experience. I've had this issue since I started with Unity, the Editor would almost always hang up whenever I do the following:
    1. open up a project, no matter what template (same with 3D, URP, HDRP),
    2. open up a script in VS 2019,
    3. press "Attach to Unity",
    4. go back to Unity and press "Play".
    Keep your "watch out for endless loops" to yourself at this point as I've been around programming for over a decade now and I'm perfectly sure that I stopped producing those after the first couple of years. The above problem happens in ALL kinds of projects and scripts for me, incl. empty ones with just the Debug.Log("whatever") in the Start() function. It does happen with and without any breakpoints set. It really seems to me that the "play" process attaches to the VS somewhere in "another" instance or something...

    However, here's what solved it for me. Instead of the steps 3 & 4 above just press "Attach to Unity and Play" (and stay away from the "Play" button in Unity whenever you are attached to it from VS) - knock on the wood, but works in 100% of the cases for me. You're welcome.
     
    Frelude, ENOUGH- and dog_funtom like this.
  50. sravan_unity

    sravan_unity

    Joined:
    Feb 12, 2020
    Posts:
    1
    ^ Adding to that, this also happens with Unity on Mac, Windows, 2017 , 2018 and 2019 ( I haven't tested 2020 yet ) versions, with Visual studio and Jetbrains Rider and on multiple projects.

    This only happens ( for me anyway ) if I have a breakpoint I know I'll hit.

    I gave up and am using Debug.Log Statements. It sure is annoying and hopefully they're fix it soon.
    If someone else found a better workaround to it, please let me know.