Reputation: 3953
When I want to edit C# Unity scripts, they open in Visual Studio. It is supposed to provide auto complete for all Unity related code, but it doesn't work.
Here you can see the missing functionality:
As seen, the transform
object does not open the autocomplete menu.
Unity version: 5.5.2f1
Visual studio 2015
Visual Studio Tools for Unity is installed
Upvotes: 379
Views: 565386
Reputation: 4336
Try this:
In the Unity Editor, navigate to the Menu bar and select Edit -> Preferences -> External Tools -> External Script Editor. Set it to Visual Studio (specify your installed version of Visual Studio).
Next, in the Menu bar, go to Edit -> Project Settings -> Player -> Other Settings. Under the Configuration section, check the API Compatibility Level and change it to your installed .NET version (in my case, I set it to .NET 4.x).
If Visual Studio is already running, switch to Visual Studio; it will prompt you to reload the project. Click Reload. Else close Visual Studio.
Reopen the .cs file from the Unity Editor, and it should now work correctly.
Upvotes: 143
Reputation: 19
If nothing in this thread resolve, install Desktop development with .NET
Upvotes: 1
Reputation: 21
Newer versions of Unity allow you to install visual studio with Unity compatibility in the setup screen, it does it all automatically for you if you check it off.
Upvotes: 0
Reputation: 2225
These actions solved the problem for my projects in Visual Studio 2022
FIX 1
FIX 2
Upvotes: 2
Reputation: 39
"Preferences" -> "External tools" -> set you exteranl tool
Thats one fix. Also for VS you can use ReSharper by JetBrains, but I recommend use Rider. That one is also free for students. It provides less performance than visual studio, but more than VS+Resharper definitely.
Have a good day, mate)
Upvotes: 2
Reputation: 125445
There is no auto-completion because the script says "Miscellaneous Files" instead of the of the name of the Project. Take a look at the image below that came from the video in your question:
The "Miscellaneous Files" message can happen for many reasons:
It can happen when you open your Unity C# file from another folder instead of opening it from Unity Editor.
This can also happen because Unity crashed while Visual Studio is still open therefore corrupting some files.
It can happen because Unity was closed then re-opened but is no longer connected to Visual Studio. When Visual Studio is opened you get "Miscellaneous Files" and no auto-completion.
This can happen when Visual Studio Tools for unity is not installed.
When you create a script from Unity then quickly open it before Unity finish processing it or before the round icon animation stuff finish animating.
Most of the times, restarting Unity and Visual Studio should fix this.
I can't tell which one is causing the problem but I will cover the most likely solution to fix this.
Fix Part 1:
Download and Install Visual Studio Tools for unity from this link. Do this while Unity and Visual Studio are both closed.
From Unity Editor, go to Edit → Preferences... → External Tools. On the External Script Editor drop down menu, change that to Visual Studio 2015.
Fix Part 2:
If newly created C# files are coming up as Miscellaneous then follow the instruction below:
From Visual Studio, go to Tools → Options... → Tools for Unity → Miscellaneous. Under Show connectivity icon, set it to true
then restart Visual Studio.
When you re-start, connection icon should now be available in Visual Studio. Click it then choose the Unity instance to connect to. The red 'x' icon should now turn into a brown checkmark icon. Now, when you create a new C# file in Unity, it should open without saying Miscellaneous.
Fix Part 3:
Still not fixed?
Re-import project then open C# Project.
Close Visual Studio.
From Unity, re-import project by going to Assets → Reimport All.
Now, open the project in Visual Studio by going to Assets → Open C# Project. This will reload the project and fix possible solution file problems.
Fix Part 4:
Still not fixed?
Fix each C# file individually.
Click on Show All Files icon.
Select the script that doesn't do auto-complete then right-click and select Include In Project.
Fix Part 5:
Not fixed yet?
Credit goes to chrisvarnz for this particular solution which seems to have worked for multiple people.
Close Visual Studio
Go your project directory and delete all the generated Visual Studio files.
These are the files extensions to delete:
.csproj
.user
.sln
Example:
Let's say that the name of your Project is called Target_Shoot
, these are what the files to delete should look like:
Target_Shoot.csproj
Target_Shoot.Editor.csproj
Target_Shoot.Editor.csproj.user
Target_Shoot.Player.csproj
Target_Shoot.Player.csproj.user
Target_Shoot.sln
Do not delete anything else.
Double click on the script again from Unity which should generate new Visual Studio file then open Visual Studio. This may solve your problem.
Fix Part 6:
If not working, check if you are having this error:
The "GetReferenceNearestTargetFrameworkTask" task was not found
Install Nuget PackageManager from here.
Restart Visual Studio.
See this answer for more information.
Fix Part 7
Make sure all of the projects are loaded. In Solution Explorer it should tell you # of # projects. If all of the projects are not showing, right click on "Solution (# of # projects)" and click Load Projects.
Upvotes: 749
Reputation: 13
Install Visual Studio and Unity Download the Visual Studio installer, or open it if already installed. Select Modify (if already installed) or Install (for new installations) for your desired version of Visual Studio. Select the Workloads tab, then select the Game development with Unity workload. If Unity is not already installed, select the Unity Hub checkbox in the Optional section of the installer. Select Modify or Install to complete the installation.
Upvotes: 0
Reputation: 37
In Unity, Edit>Preferences>External Tools
Click Regenerate project files.
Upvotes: 1
Reputation: 347
from Unity select Edit
option, then ~> Preferences...
~> External Tools
, and then turn on Built-In Packages
. I tried every solutions, and just this one helped me which I turned it on by a chance!
Upvotes: 0
Reputation: 67
If you are using Resharper with Microsoft Visual Studio, you need go to "Extensions -> ReSharper -> Extensions Manager" and install extension "Unity support". Works like magic!
Upvotes: 0
Reputation: 481
Uhm, maybe you can see my guide as an optional method. I got this problem when using Unity 2020 with Visual Studio Code 1.26 To solve problem, I follow below steps:
which mono
. For example, in my Mac, it's /Library/Frameworks/Mono.framework/Versions/Current
"omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current",
"omnisharp.useGlobalMono": "always"
Here we go....
Upvotes: 0
Reputation: 6486
This page helped me fix the issue.
Fix for Unity disconnected from Visual Studio
In the Unity Editor, select the Edit > Preferences menu.
Select the External Tools tab on the left.
For External Script Editor, Choose the Visual Studio version you have.
Click regenerate Files
You Done
Upvotes: 11
Reputation: 155
The following works for me.
Go to Edit->Preferences->External Tools->External Script Editor Select Scripting Editor
Upvotes: 3
Reputation: 363
I found another way to fix this issue in a more convenient manner:
This will kill the synchronization between Unity and Visual Studio somehow.
The next time Visual Studio will reload the project, it will prompt a warning. Just click on "Discard".
Upvotes: 21
Reputation: 814
What worked me is that I copied all the code inside the broken class and removed that file. Then, I opened an empty file with the same name and pasted back.
Result: beautiful syntax highlights came back!
Upvotes: 2
Reputation: 5851
For some odd reason, the "Game development with Unity" tool can become disabled in Visual Studio.
To fix this..
Credit to Yuli Levtov's answer on another Thread
Upvotes: 3
Reputation: 81
None of the above solutions worked for me. However I opened the ProjectName.CSPROJ
file and manually added the new file and it worked like charm
Upvotes: 2
Reputation: 1344
Update 2020 with Visual Studio Community 2019 and Unity 2019.3:
Open Visual Studio Installer as Administrator, select to modify your current installation and add "Game development for Unity"
If you add a new c# script in Unity now, and open it (automatically) with Visual Studio, it is not described as "Miscellaneous" at the top of the window but with "Assembly-CSharp", and the autocomplete works.
Upvotes: 4
Reputation: 914
Another possible fix:
For some reason, this work.
Upvotes: 2
Reputation: 514
If you have done all of the above and still isn't working , just try this:
Note: you should have updated VS.
Goto Unity > edit> preference >External tools> external script editor.
Somehow for me I had not selected "visual studio" for external script editor and it was not working. As soon as i selected this and doubled clicked on c# file from unity it started working.
I hope it helps you too.
Upvotes: 20
Reputation: 4294
one of the above methods are worked for me and I just found a solution to this problem,
1. First, go to the project directory and delete .sln
file
2. Second, go to unity and double click your script. Then Visual Studio will be open with an error,
.csproj
file. Just double click and open this from your Visual Studio editor and open the scripts folder inside the assets folder and open the scripts and autocompletion will be working perfectly fine.Upvotes: 1
Reputation: 21
I tried all of these but ended up finding out that I needed to right-click the solution in Solution Explorer and add existing items and find the C# assembly file in Window's Explorer. There seem to be a bazillion different problems that give you this error, this is likely the most simple solution. If you double click on your script from unity, it does not seem to drag the assembly along.
Upvotes: 2
Reputation: 21
Before restarting and/or re-installing VS, First try opening any other of your projects to see if Intellisence works, if it does, then issue probably lies with your current project. First, most probable victim would be the NUGET packages with pending updates. To Fix this,
Upvotes: 2
Reputation: 21
Keep in mind that if you are using the ReSharper tool, it will override the IntelliSense and show it's own. To change that, on VS, go to Extensions -> ReSharper -> Options -> IntelliSense -> General then choose Visual Studio and not ReSharper.
Upvotes: 2
Reputation: 31
Try pressing Ctrl + Alt + Space
(which toggles between suggestion and standard completion modes)
Upvotes: 3
Reputation: 3987
Credits: https://stackoverflow.com/a/47662523/10471480
In case Scripts folder is not visible:
Upvotes: 3
Reputation: 31
The issue I faced was that the C# Project was targeting a different .NET Framework (4.7.2), whereas the Unity project had a different target (.NET 3.5).
I fixed this by changing the target in Unity as-
File -> Build Settings -> Player Settings -> Other Settings -> API Compatibility Level : Set it to the .NET version you already have installed (Check your .NET Version here). In my case, it was 4.x
After this, Visual Studio worked perfectly and autocorrect was fixed too.
Upvotes: 3
Reputation: 553
My autocomplete also didn't work because Visual Studio Tools for Unity wasn't installed. So, after you install that, delete the auto generated Visual Studio files. Others said that you open file again and the problem is solved but it's not.
The trick is: instead of normally double-clicking the file, you need to open the C# file from Unity by right click and then "Open C# Project".
Upvotes: 3
Reputation: 443
I solved to install the same version of .NET on WIN that was configured in my Unity project. (Player Settings)
Upvotes: 2