I’m using Visual Studio Code 1.90.1 with the C# and Unity extensions installed, and Unity version 2022.3.31f1.
I’m making a game that tracks the player’s score. Everything was going fine until I decided to separate the code that tracks the score and updates the gamestate in response to it from the code that causes changes to said score.
After I moved the code to a new file, both scripts stopped running in Unity, along with a third entirely unrelated script. After restarting Unity, it will no longer let me import any of the three scripts, displaying the following error message:
Can’t add script component ‘Tracker’ because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.
It does this for all three scripts now, including the one I did not touch at all during these changes. Trying to debug the code in VS Code returns this error message:
No C# project is currently loaded. Please create a C# project in order to debug.
Again, I have to stress that two hours ago my code was running as C# code without errors, and now VS Code says it’s unrecognisable as C#. Additionally, the editor is autocompleting C# code when I type it, so VS Code is recognising the code as written, but won’t debug it or let me use it.
I am running Visual Studio on default settings, with just the following extensions:
- .NET Install Tool
- C#
- C# Dev Kit
- Unity
- Unity Tools (disabled)
In trying to debug this myself I uninstalled and reinstalled both the C# and Unity extensions, and attempted to run their debugging tools. C#’s debugger returns the error message above; the Unity extension won’t let me select it as an option in the debugger, despite having “debugging” listed as a feature on its extension page.
I checked Unity’s package manager to see if the Visual Studio Code package had disabled somehow, and it’s enabled, updated to the latest version supported by my version of Unity, and seemingly working as intended.
I’ve also tried disabling and reenabling my extensions in VS Code. I’ve noticed that when I do this, the code is reset to the default C# colour scheme for roughly half a second, before reverting back to a neutral colour scheme. I may be reading into this too much, but this seems to imply that VS Code reads my code as C# for half a second, and then stops, every time I refresh my extensions. Also, when I refresh the C# Dev Kit specifically, I get the following message:
Detected installation of ms-dotnettools.csdevkit. Would you like to relaunch the language server for added features?
Relaunching the language server makes the code go back to C# colours. And then it stops again.
Uninstalling and reinstalling all extensions has also not helped, same with restarting VS Code. I’m at a loss for what else to try.
Jarvis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.