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.
  2. Dismiss Notice

Official Microsoft previews Unity extension for Visual Studio Code

Discussion in 'Code Editors & IDEs' started by simon-elliston-ball, Aug 3, 2023.

  1. ryanslikesocool

    ryanslikesocool

    Joined:
    Jul 31, 2016
    Posts:
    49
    This worked for me, thanks! I had to manually add the "dotnet.defaultSolution" key to .vscode/settings.json. Regenerate Project Files in Unity settings didn't include it for some reason.
     
    sailro likes this.
  2. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    147
    Replace the legacy configuration entry with this one:

    Code (csharp):
    1.  
    2.  {
    3.             "name": "Attach to Unity",
    4.             "type": "vstuc",
    5.             "request": "attach"
    6.  }
    7.  
    And you should be good. 'vstuc' type is the important change, 'unity' was the type used by the legacy Unity debugger, 'vstuc' is used for the new Microsoft' one.

    When we generate project files, we create this launch.json with proper settings, but if the file exists we are doing nothing for now. We are thinking of auto-fixing legacy configurations and other incompatible settings in the next VS Editor package.
     
    Last edited: Aug 23, 2023
    LilGames, MousePods and Nelvin123 like this.
  3. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    511
    Fantastic! That worked.
     
    sailro likes this.
  4. JHobsie

    JHobsie

    Joined:
    Aug 3, 2015
    Posts:
    9
    Correct me if I'm wrong as the MS licencing options can be a bit awkward to navigate beyond the 2 monthly subscriptions.

    The C# Dev Kit for VS Code is not actually included in the Professional and Enterprise monthly subscription but is only included in the 'Standard + GitHub Enterprise' subscriptions which cost a lot more (I think ~£1400/£6000 a year for pro/enterprise).

    So if you fall into the category of needing a pro licence or more it would be way cheaper to use Visual Studio with a monthly sub rather than Visual Code + Official Unity Plugin? Which seems backwards.
     

    Attached Files:

  5. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    511
    So I've been using the debugger and it's been wonderful being able to Step Into and Watch variables again. However starting about 2 days ago, the time it takes for Unity to reload assemblies and compile code when the debugger is activated is really long. Yesterday I noticed all the Microsoft Visual Code extensions had updates waiting so I updated them but that hasn't changed anything. What should I be looking at?
     
    Last edited: Aug 30, 2023
  6. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    147
    Hi!

    Perhaps you should double-check your breakpoints. If you keep advanced ones like function breakpoints, exception breakpoints or breakpoints with conditions, we have to disable specific optimizations (like type load filtering) or use a lot of evaluations that can impact the global performance.

    It is also possible that your code started throwing a lot of exceptions and this is known to kill the performance especially when debugging. For that you can use an exception breakpoint to find the culprit.
     
    pKallv and LilGames like this.
  7. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    511
    Fantastic! I clicked "Clear all breakpoints" and then only added 1 breakpoint. Hit the debug > button, hit Play in Unity and it all started right up within 2 seconds.
     
    sailro likes this.
  8. jasonboukheir3

    jasonboukheir3

    Joined:
    Apr 13, 2022
    Posts:
    95
    This is awesome!!! Thank you so much! Now I don't need a Rider subscription and can use vscode for everything!
     
    MousePods and sailro like this.
  9. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    Do I really need to sign in with Microsoft to use the C# dev kit?

    Capture d’écran_2023-09-04_08-22-11.jpg
     
  10. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    260
    APSchmidt likes this.
  11. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    Nice, after I created a variable, it suggested the next one. :)

    Capture d’écran_2023-09-04_17-51-31.jpg
     
  12. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    But it doesn't know Vector2... :(

    Capture d’écran_2023-09-04_18-17-59.jpg
     
  13. jasonboukheir

    jasonboukheir

    Joined:
    May 3, 2017
    Posts:
    80
    I'm really enjoying using vscode on my project with Copilot -- it's saved me much typing.

    One slowdown is that my project is a multi-root project, and I like to refer to my other files while i'm working in Unity. I have a workspace file in my root unity project, but when I double click a c# script, Unity opens the folder, and not the workspace.

    Is it possible for me to make it so that Unity will open a particular workspace file instead of the project folder when I double click a C# script? Is there a way for me to set default workspace settings in vscode so that if it opens a folder it automatically opens the workspace?

    It presents another issue, where I have to copy my workspace settings between the folder and my workspace file. For example, I use conventional commits extension, and I have duplicated default scopes in both the workspace and .vscode/settings.json files.
     
  14. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    147
    saskenergy and jasonboukheir like this.
  15. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    Well, it seems that rebooting was necessary. Today, it knows Vector2.

    Capture d’écran_2023-09-05_08-36-08.jpg
     
    pKallv and LilGames like this.
  16. PyrateAkananto

    PyrateAkananto

    Joined:
    May 8, 2018
    Posts:
    8
    So as somebody who prefers Visual Studio Code over Visual Studio Professional and who is an "enterprise" user according to Microsoft's license terms I am now forced to buy a license for Visual Studio Professional to use this new "Unity" extension from Microsoft for Visual Studio Code? Like, seriously?!

    To be honest I currently am really frustrated about the way this is going. So far .NET and C# and Visual Studio Code had been a joy to work with and were great to be recommended to others because of their open source origin and their permissive licenses. This new licensing terms for the new closed source extensions are complicated and confusing and basically try to shove "enterprise" users over to the full-but-expensive(-and-bloated) Visual Studio Professional.
     
    jasonboukheir likes this.
  17. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,120
    After the Visual Studio for Mac announcement I have decided to try out the code editor before turning to Rider.

    Is there a list of usable and nice to have extensions to install?

    ...also can someone point me to a good, and recent, tutorial using it with Unity3d and, what I think, is the recent additions?
     
  18. Nelvin123

    Nelvin123

    Joined:
    Apr 4, 2014
    Posts:
    5
    These 4 are my favourites (besides whatever programming language/project related plugin I use, depending on what I'm working on)

    https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens
    https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments
    https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks
    https://marketplace.visualstudio.com/items?itemName=ms-vscode.hexeditor
     
    pKallv likes this.
  19. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    511
    It's just coding. I'm not sure what tutorials you need. Your coding IDE should:
    - highlight syntax
    - detect typos and errors
    - autocomplete is useful
    - allow right-clicking to view Definitions (eg: You right click on a function name in your code, select "Go To Definition" and it should show you/take you to that function. Same for variables and other definitions.
    - Rename Symbol is how to rename a var or function such that it changes EVERYWHERE in your project code files.
    - and of course a working debugger

    Extensions:
    - Unity (from Microsoft)
    - Intellicode for C# Dev Kit
    - C# Dev Kit
    - C#
    - .Net Runtime Install Tool

    And then here's one I installed because I got used to this feature when I used to code Actionscript in Flash :
    Duplicate selection or line by Greg Bacchus
    https://marketplace.visualstudio.com/items?itemName=geeebe.duplicate
    You CTRL-D and it duplicates the line of code or selection. Very useful shortcut.
     
    Last edited: Sep 7, 2023
    pKallv and APSchmidt like this.
  20. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,120
    Now I have used VSC or a few days and I must say that I like it. Will also test Rider but as I feel now it must be quite better if I should use it. However, I have never used rider so maybe it is.
     
  21. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    I just experienced some problems with autocomplete. It should be said somewhere that for VS Code autocompletion to work properly, the Unity package "Test Framework" must be installed in the project. I didn't get any warning of any kind when I deinstalled it. Lesson learnt.
     
  22. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    147
    Indeed, Test Framework is a dependency of the VS Editor Package:

    upload_2023-9-10_10-6-45.png

    I believe it was possible to remove dependencies with previous Unity version (it is clearly an issue), but I just tested with 2022.3.f1 and you cannot do that anymore -hopefully-.

    upload_2023-9-10_10-8-58.png
     
    MousePods likes this.
  23. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    Hopefully. I'm using version 2021.3.
     
  24. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,120
    I will go for VSC at this point. It is really good, and free.
     
    Nelvin123 and APSchmidt like this.
  25. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    4,402
    Welcome! :)
     
    pKallv likes this.
  26. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,120
    Is anyone aware of an extension that automatically format the code when you add a {?

    Example: I put an if statement in front of a code line and remove the } that is automatically added and place it on the line after the code line. I would like VSC to format so the code line, or whatever is in-between the {} is tabbed to the correct position.
     
    LilGames likes this.