I’m currently testing Cursor with my Unity 2022.3 (game engine) project. I’m getting along fine so far, but I have problems as soon as I create a new C# script in Unity. The file appears in Cursor, but cannot be referenced in other scripts:
“The type or namespace name ‘TestEnemy’ could not be found (are you missing a using directive or an assembly reference?) CS0246”
I temporarily changed the editor in Unity back to Visual Studio 2022 and then back to Cursor again, after which the script was recognized and I was able to reference it.
In Unity, I have activated the package for Visual Studio Code.
I have activated the following extensions in Cursor:
This sounds like Unity is doing some work to detect these files and add them into your Unity project. With a bit of research, it looks like this is also an issue in VSCode too!
Unfortunately, quite a few editors do this (Android Studio is a good example), where they will built some files and configs for your project in the background, so you can get up and running quickly. This isn’t a bug in Cursor or VSCode, but a feature in Unity that wouldn’t happen in Cursor.
What this means is, when you work on it in VSCode, those usually automatic jobs aren’t done, breaking things like references to new files that would usually work in Cursor.
There may be a solution on line, a fix for VSCode would also work in Cursor, but for now you may have to leave Unity running, and switch to it when you make a new file so it can build the references correctly!
I happen to be a Unity expert and have been using this linked solution for 4+ months. It does in fact resolve the issues mentioned here and works pretty well out of the box after cursor has been selected in Unity preferences.
Some issues may still occur if intellisense of some editor service crashes, runs out of memory, but you should be able to find those issues in logs. Also note that the way you open Cursor to the Unity project also affects if it loads normally or not.
While there is no official package, it seems that this is the easy choice for many (170 stars on that repo). It’s also been mentioned in this blog post:
I’ve checked the git history of fork and didn’t see any suspicious changes like backdoors or keyloggers so far, but I would be wary of this convenience as nothing would prevent this anonymous author from adding malicious code to it in the future to benefit from its popularity.
Unity hasn’t bothered to create an official version yet, but better move to the official version which should become available once Unity realizes what’s happening in the coding world and publishes their official Cursor extension.
Thanks for your answers. I’ve already seen the mentioned solution in a previous search, but because it’s not an official Unity repo, I’d rather not use it. I don’t create new scripts very often… so I’ll just work around it by switching to Visual Studio in the settings temporarily.