Search Unity

Question How to debug Unity with Vscode in 2022?

Discussion in 'Editor & General Support' started by qwerfd, Aug 20, 2022.

  1. qwerfd

    qwerfd

    Joined:
    Feb 10, 2017
    Posts:
    1
    Since official unity debugging extension has been deprecated, how does one debug a unity application with vscode? Official documentation still says that no longer maintained extension is the way to go.

    I've been crawling the web for hours and I can't seem to find an answer on how to do it without the extension. And all the launch.json files I've been able to find aren't working, or I maybe I just don't know how to use them.

    Any help is appreciated.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    This may help you with intellisense and possibly other Visual Studio integration problems, including the debugger.

    Sometimes the fix is as simple as doing Assets -> Open C# Project from Unity. Other times it requires more.

    Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

    Barring all that, move on to other ideas:

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    Also, try update the VSCode package inside of Unity: Window -> Package Manager -> Search for Visual Studio Code Editor -> Press the Update button

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874
     
    romans5 and DevDunk like this.
  3. Leonstar0

    Leonstar0

    Joined:
    Feb 23, 2017
    Posts:
    2
    Unfortunately, you've missed the point of qwerfd's post.
    OP is using "Visual Studio Code" or "vscode", which is a completely different product to "Visual Studio".

    Your solution doesn't apply here.

    To address qwerfd's question. I don't know either. The unity debugger for VSCode still kinda works (I've heard reports it crashes in some cases), and I'm hoping the community will pick it up and support it. Otherwise, might want to consider prepping yourself/your team to move to Visual Studio if you find your use case for debugging exceeds the capabilities of the soon-to-be-or-currently-being-depreciated vscode extension.

    Currently I'm just sitting on my laurels until our team encounters a significant blocker.
     
    MaxLohMusic and bn-l like this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Unfortunately you failed to read my post, which advises you to update the VSCode Package and also provided direct link to somebody who got VSCode working with a workaround. I'll copy it here in case you missed it:

    ... and yet is integrated using precisely the same mechanism that Ryder and VS and formerly Mono were integrated with... Do you have a point?

    Don't worry, I've had a TON of people respond to my posting the above saying "Your post was for VS but it worked for VSCode too... Thanks!" You're just not one of them.

    Meanwhile, we are all eagerly awaiting your first helpful post here.
     
    z80561b and Pnvanol like this.
  5. Leonstar0

    Leonstar0

    Joined:
    Feb 23, 2017
    Posts:
    2
    Damn. I'm sure you have helped a lot of people man. Didn't mean to come off as rude, sorry about that mate.

    1. The vscode package for unity, afaik, only helps with regenerating project files for vscode.
    https://docs.unity3d.com/Manual/com.unity.ide.vscode.html
    It's the files themselves that hook into omnisharp tho, I don't think the package actually has any active elements/ you could remove the package once you've generated the files. (Did a small trial in my project by blasting away the extension, restarted ominsharp in vscode, and still gotz my intellisense)

    2. I missed that OP was having trouble installing the extension, I thought they were just asking for an alternative to the extension: The answer to which is no, there is not.
    However, if you want to use the debugger you need to force vscode to install the depreciated extension, I think you can do that by going to the webpage and clicking install on the page:
    Debugger for Unity - Visual Studio Marketplace
    I dunno if the launch options for vscode are working any more, but I can confirm the "attach to unity" still works (although it's finicky / takes some time / may need to trigger it multiple times for it to work). To attach the debugger to unity:
    a) Enable debug mode in unity by clicking the lil' bug symbol in the bottom status bar
    b) in vscode, click ctrl-shift-p to bring up the command plane, type in "Unity attach debugger" and select your instance of unity.
    c) Wait a while (few mins) and if it doesn't work, try it again till it does. I dunno why it's finiky like this, but I just spent like 30 minutes trying to get it to work on my end.

    3. The vscode extension "C# for vscode" has limited support for debugging (powered by omnisharp, I assume transitivity in terms of these being limitations of omnisharp itself and not the extension (I could be wrong tho)):
    GitHub - OmniSharp/omnisharp-vscode: Official C# support for Visual Studio Code (powered by OmniSharp)

    • Debugging support for .NET Core (CoreCLR). NOTE: Mono debugging is not supported. Desktop CLR debugging has limited support.
    No mono debuggings supported, which is what Unity is. To get around this, VS has some stuffs to get the debugger to attach to unity (Visual Studio Tools for Unity). This work for VS is completely different to the project used by VScode to get the debugger to work (GitHub - Unity-Technologies/vscode-unity-debug: Unity debugging support for VS Code).
     
    Kurt-Dekker likes this.
  6. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    429
    xmarleauFFG and edusuko like this.
  7. plan-systems

    plan-systems

    Joined:
    Mar 8, 2020
    Posts:
    44
    It is really Unity's official position that if you're using VSCode then too bad and deal with broken/legacy tools? This is a not a good look for Unity if they can't maintain their tools for VSCode.

    In any case, I find this
    launch.json
    entry helpful -- it automatically finds the process info w/o putting an absolute path in your project:

    Code (JavaScript):
    1.  
    2.         {
    3.             "name": "Unity Editor",
    4.             "type": "unity",
    5.             "path": "${workspaceFolder}/Library/EditorInstance.json",
    6.             "request": "launch",
    7.         },
    8.  
     
    Last edited: Nov 23, 2022
  8. vinepest

    vinepest

    Joined:
    Feb 5, 2023
    Posts:
    1
    Nah, none of the suggested solutions here worked for me. Screw it, I'm using Visual Studio Community Edition, it works like a charm. It's slow, but I'm sick of the neglected VSCode integration.
     
  9. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Does "Step Into" work for you? It does not for me. The old debugger extension would crash but Unity/the game continued running happily. This new Debugger by Deity just stops doing its thing when using Step Into and Unity editor completely freezes and requires going through Windows Task Manager to kill it. : /
     
  10. IvanRoyLoewen

    IvanRoyLoewen

    Joined:
    Apr 19, 2016
    Posts:
    3
    I just switched to VS Code because VS Community got to slow. I think I might just code in VS Code, and debug in VS Community when I need to. Not ideal, Not sure why Unity wouldn't keep updated with VS Code..
     
    ThomasVeil likes this.
  11. ThomasVeil

    ThomasVeil

    Joined:
    Aug 7, 2014
    Posts:
    7
    Unity announced in another thread they'll not continue VSCode support, including this debug plugin. Because MS doesn't wanna take care of it ... maybe MS would be the better party to poke about this?!
    Looks like the open source attempt is also stuck.

    I think I'll do that too as it's not working reliably for me. It seems Community has also more debugging features. Switching for debugging is not too hard right now.
     
    plan-systems likes this.
  12. npatsiouras_ntua

    npatsiouras_ntua

    Joined:
    Feb 11, 2023
    Posts:
    16
    As if the VS package is better....

    Every now and then I try to debug and after attaching to the unity process (while in-editor), VS complains that it can't hit some code. Sometimes that makes sense, other times it just needs to be reattached for some reason and all those breakpoints become breakable.

    This time, I've just lost about 1h trying to fix it. Also tried Rider, worked once, then it too whined about not being able to find things. Worst part is, in VS, after attaching, I can see the dlls being loaded in Modules window and their pdbs too.
     
  13. DarkStoorM

    DarkStoorM

    Joined:
    Feb 25, 2015
    Posts:
    2
    I just found this thread after giving VSCode another try. Had some problems with getting the debugger to run, but the above was the solution for me.

    I first ran the .NET: Generate Assets for Build and Debug command from the Command Palette.

    The create launch.json couldn't automatically pick up the path in my project, so I replaced the configurations property with the above snippet. This was my launch.json file

    Code (JavaScript):
    1. {
    2.   "version": "0.2.0",
    3.   "configurations": [
    4.     {
    5.       "name": "Unity Editor",
    6.       "type": "unity",
    7.       "path": "${workspaceFolder}/Library/EditorInstance.json",
    8.       "request": "launch"
    9.     }
    10.   ]
    11. }
    12.  
    After that, I installed the unity.unity-debug extension, which is sadly not being maintained anymore.
    I put a breakpoint for a test, hit F5 and the debugger in my VSCode actually started working.

    I don't know if it matters, but I'm running the following extension versions:
    • ms-dotnettools.csharp v1.25.7
    • unity.unity-debug v3.0.2
    [edit]
    After poking around with the settings it stopped working, so when you set everything up and you see the following in your Debug Console and nothing else, restart your Unity Editor:



    I'm not entirely sure, but I think the debugger just couldn't attach to the correct process, so after restarting and trying again, it started loading all assemblies and it worked again. It's so buggy with VSCode, that it seems to be just a luck of the draw.

    The console will spit some errors when hovering over the types, but that doesn't really matter

     
    Last edited: May 18, 2023
    edusuko likes this.
  14. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Sounds like what some have reported above. If you try to "step into" code, the debugger crashes. You're hooped at that point and have to restart VS Code. Same when hovering over certain types of data. Some will work, some will report an error and things keep on happily chugging away, others, it kills the debugger and it just stops outputing anything.
     
  15. Scorpin

    Scorpin

    Joined:
    Jun 27, 2018
    Posts:
    4
    So... We must go to Visual Studio again to just keep debugging our games/apps in Unity... Some answer about why don't just keep updating the extension in VSCode as official Unity debugger?
     
    Unifikation likes this.
  16. peterfiftyfour

    peterfiftyfour

    Joined:
    Jan 8, 2016
    Posts:
    20
    After endless issues with this I think I'm just gonna swap to Rider. Sooo frustrating. Wish unity could spare some resources to sort it out
     
    Dinamytes and thexdd like this.
  17. joseph114591452

    joseph114591452

    Joined:
    Mar 14, 2020
    Posts:
    28
  18. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
  19. marco-vidaurre

    marco-vidaurre

    Joined:
    Dec 15, 2012
    Posts:
    7
    WOW , I just looked up this question now and there's the answer. Thanks! npatch
     
  20. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    475
    Woah I didn't see that coming, kudos to Microsoft.