Unity Scripts edited in Visual studio don't provide autocomplete
Asked Answered
I

37

370

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:

Video of missing autocomplete feature

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

Indisposed answered 4/3, 2017 at 15:5 Comment(7)
translate.google.com :) Making a video and uploading it to YouTube for describing the error +1 xdYeo
Ok, All try... I have a Little problem with scripts. When Im writing C# scripts for Unity with Visual studio it seems like I`m working in notepad, there are no "tips" (correct?) and I must write it very slowly. Please, watch the video. At start is normal situation (from tutorial), second part is my problem.Indisposed
I'd say you are asking about 'autocompletion', not tooltips.Sempiternal
What Visual Studio version and what Unity version?Palma
Unity version: 5.5.2f1 / Visual studio 2015 / Visual Studio Tools for Unity is installedIndisposed
This article here documents all the possible solutions pretty well: blog.terresquall.com/2020/11/…Sieve
Strongly recommend jetbrains rider as a substitute for visual studioBeale
P
743

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:

enter image description here

The "Miscellaneous Files" message can happen for many reasons:

  1. It can happen when you open your Unity C# file from another folder instead of opening it from Unity Editor.

  2. This can also happen because Unity crashed while Visual Studio is still open therefore corrupting some files.

  3. 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.

  4. This can happen when Visual Studio Tools for unity is not installed.

  5. 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:

  1. Download and Install Visual Studio Tools for unity from this link. Do this while Unity and Visual Studio are both closed.

  2. From Unity Editor, go to EditPreferences... → External Tools. On the External Script Editor drop down menu, change that to Visual Studio 2015.

    enter image description here


Fix Part 2:

If newly created C# files are coming up as Miscellaneous then follow the instruction below:

  1. From Visual Studio, go to ToolsOptions...Tools for UnityMiscellaneous. Under Show connectivity icon, set it to true then restart Visual Studio.

    enter image description here

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

    enter image description here


Fix Part 3:

Still not fixed?

Re-import project then open C# Project.

  1. Close Visual Studio.

  2. From Unity, re-import project by going to AssetsReimport All.

    enter image description here

  3. Now, open the project in Visual Studio by going to AssetsOpen C# Project. This will reload the project and fix possible solution file problems.

    enter image description here


Fix Part 4:

Still not fixed?

Fix each C# file individually.

  1. Click on Show All Files icon.

    enter image description here

  2. Select the script that doesn't do auto-complete then right-click and select Include In Project.

    enter image description here


Fix Part 5:

Not fixed yet?

Credit goes to chrisvarnz for this particular solution which seems to have worked for multiple people.

  1. Close Visual Studio

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

  3. 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

  1. Install Nuget PackageManager from here.

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

Palma answered 4/3, 2017 at 17:20 Comment(25)
Thanks for the miscellaneous files pointer! Closing VS, deleting the VS projects and sln, and then double-clicking a script in Unity (therefore regenerating the project files and reopening VS) fixed it for me. I'd recommend trying that before the "reimport all" button as that is lunch/overnight for non-trivial projects.Was
That's a good advice. Hope anyone reading this can see this commentPalma
This is most times caused by creating new scripts or moving them to different folders within Unity. Whenever restarting Unity and VS doesn't solve it, I simoly also delete the *.csproj and *.sln files and start Unity than. This usually worksSlang
Yes, deleting files may also work since VS will re-generate the data back again. NotePalma
Thank you. #2 worked for me. Why does "Show connectivity icon" (setting it to true) fix this?Libby
@Libby Setting it to true won't simply fix it. You need to do the next step in part 2 which will connect Visual Studio to Unity instance. If simply setting it to true worked then you are lucky. You are welcome.Palma
Odd, that it worked for me. I just found another solution, which I posted below, which is unloading and reloading the project.Libby
@Was solution worked for me after trying all of these other suggestions.Avid
@Avid Good. Since that worked for multiple people, I have updated my answer to also include that.Palma
I followed all of the instructions except step 5 above and nothing worked, but before deleting all the files in step 5 I closed visual studio and reopened it using the sln file from the file explorer and everything showed up properly. After that I closed visual studio and opened a script file from Unity and it was still working. Before opening visual studio from the sln file from the file explorer I had closed VS multiple times throughout the process listed above and reopened it by clicking on a CS file in Unity or by "Assets --> Open C# Project"Experimentation
@Experimentation Looks like you combine #3(Assets --> Open C# Project) and #5 to me. Glad you got it workingPalma
Another (easier) way to manually add files to the solution/project is to go File>Move Script.cs>Assembly-CSharpWiden
The Navigation Bar (where the Miscellaneous files appears) can be opened going to Tools -> Text Editor -> All languages -> Show Navigation Bar. If it doesn't show up change the file selectionHagen
I have the Nuget package manager error. In VS 2017 this package is included with the installation of the Unity Tools in VS, if you execute the installer and click "Modify" it will show up in the list. You can either try to repair installation, or remove both packages,and then add them again if you don't want to lose your settings. My problem was that the properties window could not be shown, there must be some error. Updating VS and reinstalling the unity tools and package manager worked.Hagen
excluding file from project then including back solved the problem in my caseChela
For me this worked: open the .sln file in Explorer (found in your Unity project root folder) instead of double clicking on the C# script file in Unity.Blas
The same problem also happened with me in Unity 2019.2 & Visual Studio 2019. But, solved it with your solution. Now VS running smooth as butter.Levant
This right here is the ONLY thing that worked for me. Specifically, "In Unity go to Edit -> Preferences -> External Tools. On the External Script Editor drop-down menu, change that to Visual Studio."Roxie
Fix part 1 worked for me using Unity 2019.3 and visual studio community 2019. Thanks!Castrate
Thanks, "Fix Part 1" worked for me. External Script Editor set to "Visual Studio 2019 (Community)". I suspect the problem coming with Visual Studio installed prior UnityWhoremaster
You are a savior my friend, Thanks for the help. First step worked for me.Legist
Fix 3 and 5 work for my case.Enki
Good sir @Programmer, I have issues for autocomplete in the Plugin I am creating (located under Packages), but only for UnityEngine* imports. This is only happening with (relatively) up-to-date UnityEditors, not the ones from last year. Anyone experienced anything similar?Monitorial
Opening C# Project isn't opening it in Visual Studio.Lymanlymann
Solved with part 1Swirsky
T
138

Try this:

  1. 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).

  2. 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).

  3. If Visual Studio is already running, switch to Visual Studio; it will prompt you to reload the project. Click Reload. Else close Visual Studio.

  4. Reopen the .cs file from the Unity Editor, and it should now work correctly.

Tribe answered 17/6, 2019 at 10:21 Comment(10)
Same for me, thank you! Tried everything but only this fixed it.Irresolute
this is the REAL answer. This needs to be at the top!Carpeting
This worked for me too. Also, one additional thing I did in Unity 2020.2.0a13 was uncheck and check again the mark at Edit/Project Settings/Player/Other Settings: Auto Graphics API. After restart of Visual Studio, autocomplete was back :DBlamable
This is the only method that worked for me, thanks a lot!Changsha
please vote for this one! this is the solution in 2021Prestigious
It worked for me. ThanksHeaps
Hi. That option is grayed out. How can I change it?Lumbricoid
Using Unity on Linux, I also needed to install 'mono' and turn on 'use global mono: always' as per an error in the vscode server log after using this answer. After that we are all set. Thank you!Mendelson
This is the one this is the REAL answer guys, this is the accepted answer, this is what fixes exactly this problem.. Net 4.x in the player, and Setting the External editor..Boniface
Unity -> Settings for Macos in 2024 (stop looking for preferences if its not there lol)Mean
T
21

I found another way to fix this issue in a more convenient manner:

  1. Select the broken file in Solution Explorer.
  2. Open its Properties.
  3. Switch field "Build Action" from "Compile" to "None".
  4. Then switch it back to "Compile".

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".

Thingumabob answered 30/10, 2017 at 19:20 Comment(0)
S
20

If you have done all of the above and still isn't working , just try this: Note: you should have updated VS. Screenshot from visual studio

Goto Unity > edit> preference >External tools> external script editor. Unity screenshot 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.

Selfregulating answered 22/4, 2020 at 1:37 Comment(1)
Great for people who had visual studio installed before Unity, this worked for me after also installing the VS tool for Unity.Wershba
L
17

Unload and reload the project, in Visual Studio:

  • right click your project in Solution Explorer
  • select Unload Project
  • select Reload Project

Fixed!

I found this solution to work the best (easiest), having run into the problem multiple times.

Source: https://alexdunn.org/2017/04/26/xamarin-tips-fixing-the-highlighting-drop-in-your-xamarin-android-projects/

Libby answered 21/11, 2017 at 21:28 Comment(2)
Thanks for the help! This worked, but I feel that we are back in '90s and we need to restart Windows, only this time it's VS 2017.Outbreed
Thanks this worked for me a treat! Appreciate you putting this up!Haarlem
N
12

This page helped me fix the issue.

Fix for Unity disconnected from Visual Studio

enter image description here

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

Ninfaningal answered 6/1, 2021 at 10:54 Comment(1)
This solution worked for me. Then, after opening a script file, the Visual Studio editor recommended me to install Tools for Unity, and after the update the auto-complete works just fine. Thanks!Putnam
I
9
  1. Select project in Visual Studio
  2. Click "Refresh" button

enter image description here

Inspan answered 14/12, 2017 at 11:58 Comment(1)
Whoa! Nothing else helped for me; Re-Install of VS, even reinstalling Unity so that it reinstalled VS, deleting .sln and .cjsproj files so that they were regenerated. nothing helped .. but finally a simple click in the solution explorer to show folders seemed to do it :oBedlamite
P
4

I hit the same issues today using Visual Studio 2017 15.4.5 with Unity 2017.

I was able to fix the issue by right clicking on the project in Visual Studio and changing the target framework from 3.5 to 4.5.

Hope this helps anyone else in a similar scenario.

Poon answered 2/12, 2017 at 22:26 Comment(0)
L
4

Two Alternative Options:

Fix 1

@singleton pointed me in this direction. Instead of changing the target in Visual Studio you should change it in Unity since the project is auto-generated.

First delete the auto generated Visual Studio files: .csproj .user .sln

Then from within Unity go to PlayerSettings and under 'Other Settings' change the 'Scripting Runtime Version' from Stable 3.5 to Experimental 4.6.

However, that didn't fix it for me.

Fix 2

I noticed all of the references to Unity related code was marked with a yellow warning. Check your error logs and see if this is the case. In particular see if you get the following error: getreferenceNearestTargetframeworkTask

If so try: Start Visual Studio Installer again.

On the Build Tools 2017, click Modify,

Ensure that "Nuget targets and build tasks" are ticked. This should become ticked if you click on Universal Windows Platform development.

Leatriceleave answered 12/12, 2017 at 15:16 Comment(0)
C
4

Update 2020 with Visual Studio Community 2019 and Unity 2019.3:

  1. Open Visual Studio Installer as Administrator, select to modify your current installation and add "Game development for Unity"

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

Clomp answered 21/4, 2020 at 17:15 Comment(0)
D
3

i found my solution by creating the .cs file from visual studio itself instead of unity editor

  • right click on project folder in solution explorer
  • add > new item
  • type "unity" on the search field on the top right
  • select "CSharp MonoBehaviour"
  • name your script on the bottom and click Add
Dysthymia answered 1/12, 2017 at 5:5 Comment(2)
What if you have already created the scripts but then suddenly, this issue arises, are you going to delete all the scripts and create them again from Visual Studio?Palma
@Palma well i'd use your Part 4 solution to fix the already error script but i always use visual studio to create new script because none of your solution stopped the new script from getting error unless i created the file from visual studioDysthymia
B
3

In my case, correct .net version was not installed on my PC. I install the .net 3.5 on my pc and that worked for me.

Brunner answered 19/12, 2017 at 15:54 Comment(1)
Your Answer gave me the Idea to Change the API Compatibility Level in Unity Player Settings from .Net 2.0 to .Net 4.x. And then reload the project in Visual Studio. Now everything works fine.Tribe
A
3

For Windows or macOS:

Download/Install the Visual Studio IDE (with Unity Tools)

When installing, make sure you include installation of

Game development with Unity

enter image description here

Then using Unity (you can double click one of your C# files), open a new C# project and the Visual Studio IDE should open with your new project structure.

enter image description here

From there, you should be able to see what you are looking for.

For example:

enter image description here

enter image description here

For Linux (suggestion):

Try Monodevelop - Additional Information, it provides code completion/hints.

Angelus answered 21/1, 2018 at 18:10 Comment(0)
G
3

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".

Gait answered 14/7, 2018 at 2:20 Comment(0)
H
3

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.

Hemp answered 1/10, 2018 at 16:3 Comment(1)
This worked for me. I changed my API Compatibilty Level to .Net 4.x, and then Visual Studio asked to Reload the Project. I reloaded the project. Then I closed Visual Studio, Opened cs file from Unity Editor and now everything works fine.Tribe
S
3

Try pressing Ctrl + Alt + Space (which toggles between suggestion and standard completion modes)

Silique answered 7/8, 2019 at 2:9 Comment(0)
L
3

For some odd reason, the "Game development with Unity" tool can become disabled in Visual Studio.

To fix this..

  1. Open Visual Studio
  2. Go to Extensions → "Manage Extensions" → Installed
  3. Find "Visual Studio 2019 Tools for Unity"
  4. If it is disabled, enable it
  5. Restart VS

Credit to Yuli Levtov's answer on another Thread

Liveried answered 16/8, 2020 at 12:18 Comment(0)
M
3

The following works for me.

Go to Edit->Preferences->External Tools->External Script Editor Select Scripting Editor

enter image description here

Mcdevitt answered 2/6, 2021 at 12:58 Comment(0)
V
2

I solved to install the same version of .NET on WIN that was configured in my Unity project. (Player Settings)

Votary answered 16/5, 2018 at 2:46 Comment(0)
A
2

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

Amberambergris answered 30/8, 2018 at 20:27 Comment(0)
M
2
  • Go to Options on the Tools menu and then select Documents in the Environment node. (If Documents does not appear in the list, select Show all settings in the Options dialog box.)
  • Put a tick on "Miscellaneous files in Solution Explorer" and Click OK. (This option displays the "Miscellaneous Files" node in Solution Explorer. Miscellaneous files are files that are not associated with a project or solution but can appear in Solution Explorer for your convenience if you tick this option.)
  • Locate your file in the Solution Explorer under "Miscellaneous Files". Then drag and drop your file to where it should belong and voila! This will copy the file to where you drop it. You may now safely delete the older file under Miscellaneous Files folder if you wish to do so

Credits: https://mcmap.net/q/93453/-visual-studio-project-shows-up-as-quot-miscellaneous-files-quot


In case Scripts folder is not visible:

  • Click on "Show all files" in Solution Explorer
  • Locate the Scripts folder.
  • Right Click on Scripts and select "Include in Project"
Montpelier answered 7/11, 2018 at 12:21 Comment(0)
P
2

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!

Polyandrist answered 8/1, 2019 at 21:37 Comment(0)
H
2

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.

Historicism answered 7/8, 2019 at 17:1 Comment(0)
I
2

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,

  1. Right click on references
  2. Proceed to Manage NUGET Packages Under NUGET Packages
  3. proceed to updates Install Updates and recheck Intellisence
Indra answered 21/8, 2019 at 13:36 Comment(0)
A
2

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.

Alienate answered 25/8, 2019 at 23:56 Comment(0)
H
2

Another possible fix:

  1. In the project window, click on the Assets folder
  2. Right click, and Create -> C# Script
  3. Double click that, and wait.

For some reason, this work.

Headmaster answered 23/4, 2020 at 2:34 Comment(0)
L
2

"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)

Lewes answered 21/6, 2022 at 7:52 Comment(2)
Also if you didnt installed package for unity development for VS you can go Visual Studio Installer -> Workloads -> GameDev. with UnityLewes
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Scutiform
C
2

These actions solved the problem for my projects in Visual Studio 2022

FIX 1

  • Solution
    • Assembly-CSharp (right-click)
      • Load Entire Dependency Tree

FIX 2

  • Solution
    • Assembly-CSharp
      • References
        • Double click on any lib to force loading
Caseworm answered 15/7, 2022 at 10:56 Comment(0)
B
1

Try with combination: Ctrl + Alt + Space

Brandonbrandt answered 10/10, 2019 at 6:31 Comment(0)
S
1

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, enter image description here

  1. Then click ok and close Visual Studio editor.
  2. Finally, turn off your Windows Defender and then go to your project directory and there will be .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.
Safeguard answered 25/2, 2020 at 5:2 Comment(0)
M
1

If nothing in this thread resolve, install Desktop development with .NET enter image description here

Merrymerryandrew answered 27/9, 2023 at 1:0 Comment(0)
D
0

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:

  1. In stall C# plugin in Visual Studio
  2. Install Mono from this https://www.monodevelop.com/download
  3. Let see where Mono is installed in your Mac by this command which mono. For example, in my Mac, it's /Library/Frameworks/Mono.framework/Versions/Current
  4. Back to C# plugin, let open its setting and change below in setting.json of plugin:
    "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current",
    "omnisharp.useGlobalMono": "always"

Here we go....

Decimal answered 15/11, 2021 at 9:33 Comment(0)
M
0

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!

Mochun answered 15/12, 2021 at 12:42 Comment(0)
P
0

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!

Plasty answered 29/3, 2022 at 23:4 Comment(0)
F
0

In Unity, Edit>Preferences>External Tools Click Regenerate project files.enter image description here

Fala answered 6/4, 2022 at 11:32 Comment(0)
E
0

You install this? unity

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.

Eonism answered 22/4, 2022 at 17:42 Comment(0)
D
0

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.

Durmast answered 13/6, 2023 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.