Use the Debugger for Unity plugin in VS Code to debug (2023 latest version)

question

Changed the development machine and reinstalled the development environment. Suddenly found that Visual Studio Code can not be used to debug Unity.

Obviously the process is carried out according to the official Unity tutorial 2023.1 , but when creating the Launch.json file, the Unity Debugger option cannot be displayed.

Description: Debugger for Unity is an unofficially supported, officially recommended, and most widely used Unity debugging plug-in on Visual Studio Code. If you haven't configured Unity Debugger, you can go directly to the official documentation | Debugger for Unity - Visual Studio Marketplace to configure it. This article is regarded as a supplement to the official documentation to solve the problem that the debugger cannot be added after following the official documentation.

The originally intended steps were:

The resulting steps are:

environment

  • Unity Version: 2021.3.16f1

  • VS Code Version: 1.74.2

  • Version of the Debugger for Unity: 3.0.2

  • Version of C#: v1.25.1 (if your version is also v1.21.13+, then you probably encountered the same problem as me)

identify the problem

Click on the Visual Studio Code plugin repository, open Debugger for Unity, and see that the plugin was last updated in 2020, and the interface clearly says: This extension is enabled because it is not being maintained.

Then click on the github address of the plug-in , and encountered a bunch of victims in Issues.


Is this repository deprecated? It has been ten months since the last update. Can the latest version of this plugin still work?


Can't you make an official statement? Can you explain the situation of this plugin? He's all broken...


现在都2022年底了,还是没看到官方通知。官方Unity文档里仍然说它被推荐。


团队的回答也很直接:

简单来说,我们很忙,没钱没人来维护这个项目。我们建议你换个IDE(不要用VS Code了),比如用Visual Studio Community。或者JetBrains Rider也行。

好吧,这个就是官方的态度,不要用了。


即使2023年他们仍把Visual Studio Code和这个插件放在最新文档里,但是正如文档里所说,这个Debugger for Unity拓展插件并没有被正式支持(Not Ffficially supported by Unity)。

说的还是太委婉了,直接点说:这个拓展插件我们不维护了,爱用不用。

甭管别的博客里有多推荐,不推荐了就是官方的态度。

解决方案

要么就听官方爸爸的,开发的时候用Visual Studio Code,调试的时候用Visual Studio得了……

要么我就想凑合用能不能行?

能!

如何在新的Visual Studio Code+Unity环境里使用Debugger for Unity进行调试

之所以你创建不了Unity Debugger,是因为C#插件在v1.21.13后,把标识符从ms-vscode改成了ms-dotnettools了,Unity Debugger又没有更新,所以找不到。

两个方案:

方案1.降级(不推荐)

找到c#插件,通过手动安装C# v1.21.12.vsix 或 自动降级的方式把C#版本回退到1.21.13以前

方案2.躲bug生成Launch.json(推荐)

说来说去,只是因为C#插件升级后,Debugger for Unity识别不到C#文件导致无法生成调试的配置文件罢了。那么我们不在C#文件中去生成不就好了?

No environment to choose · Issue #202 · Unity-Technologies/vscode-unity-debug (github.com)

  1. 随便创建一个txt文件,如:test.txt

  1. 点击这个text.txt文件后,进入调试页签,如图:

  1. 点击小齿轮就可以看到Unity Debugger啦,点击它后就生成了能用的Launch.json,如图:

方案3.手动配置Launch.json

  1. 先随便生成一个Launch.json(如果已经有了,跳过这一步)

  1. 再替换这个json的内容(或者手动合并json)

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Unity Editor",
            "type": "unity",
            "path": "/d:/workspace/unity/learn/CSharpLearn/Library/EditorInstance.json",
            "request": "launch"
        },
        {
            "name": "Windows Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "OSX Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "Linux Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "iOS Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "Android Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "Xbox One Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "PS4 Player",
            "type": "unity",
            "request": "launch"
        },
        {
            "name": "SwitchPlayer",
            "type": "unity",
            "request": "launch"
        }
    ]
}

大功告成,终于又可以用Visual Studio Code调试啦!

参考

No environment to choose · Issue #202 · Unity-Technologies/vscode-unity-debug (github.com)

Unity - 手动:集成开发环境 (IDE) 支持 (unity3d.com)

Debugger for Unity - Visual Studio Marketplace

Guess you like

Origin blog.csdn.net/nick1992111/article/details/128580845