Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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:
    31,274
    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
     
    DevDunk likes 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.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    31,274
    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.
     
    Pnvanol likes 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:
    414
    edusuko likes this.
  7. plan-systems

    plan-systems

    Joined:
    Mar 8, 2020
    Posts:
    28
    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