Unity hangs when opening C# Script - c#

Every time I try to open a C# Script inside Unity, it immediately hangs and doesn't even open Visual Studio, this started happening after I updated Visual Studio 2017 twice, the first one was an incomplete installation since my computer restarted then the second one was completed version.
Unity still works normally for all things except opening a C# script. I tried changing the External Tools Preferences in the Edit between Visual Studio 2017 and Visual Studio 2017 (Community) but both did nothing.
When Unity hangs, I can only use Task Manager to close it and MonoDevelop isn't one of the options in the External Tools Preferences

Can you open Visual Studio when Unity is not open? Which version of Unity are you using for your project? Are you using Unity Hub to manage your versions?
Steps to try:
Reinstall VS (update to 2019 optional)
Close all background services related to VS and Unity.
If all else fails, you can clean the registry before reinstalling.

Uninstall both Unity, VS and any dependency that you have installed. Then go to Hub and download your required version with all the required dependencies.
Doing this will remove any inconsistency and also you will not have to do the external tool reference yourself.

Related

Unity Namespaces aren't available

I wanted to continue coding where I left after sleeping, but suddenly as I open my Code in Visual Studio and tried to work on my code while having using UnityEngine.UI or using UnityEngine.EventSystems standing at the top, it just says that the type or namespace "UI" or "Eventsystems" doesn't exist in the namespace "UnityEngine". And I also can't use using TMPro. I don't know if thats all I can't use.
I've now just restarted my pc, reselected Visual Studio 2022 17.2.5 in Unitys external tools and uptaded Visual Studio and it sill doesn't work.
Maybe it's important to know that restarting my Unity project isn't working.
How to fix that and how to prevent it from happening again?
Open Unity and go to Window > Package Manager. In the Package Manager window, select In Project from the dropdown as shown below.
In the list of packages, find Visual Studio Editor and update it to the latest version.
Close all Visual Studio windows, go to Edit > Preferences > External Tools, and regenerate project files (In your case, the External Script Editor is Visual Studio).
Reopen any script in your project and the error should disappear.

Unity Visual Studio 2017 Freeze and Crash

I work with Unity, and recently I came across some sort of bug with Visual Studio. For some reason one day the Script Editor stopped working.
When I first open it up through Unity, it would open as usual and seem fine, but after 5 seconds of interaction, Visual Studio would then freeze and crash without an error report. Following tries with the editor would just crash almost right away.
I did some research and found out that it was some sort of problem with Unity's MEF Cache, the Microsoft Documentation would ask me to do the following: Delete the following file: "%localappdata%\Microsoft\VisualStudio<version>\ComponentModelCache" and if the problem continues, I should run this line of code on VS' CMD as a administrator "devenv /setup".
I tried both methods with Visual Studio, but neither seemed to work, only to return to being fine for 5 seconds before freezing and crashing.
I have updated Visual Studio 2017 to the newer version and performed the same method, but the problem persists.
I would like to know if anyone have any solutions to my situation, if I should try reinstalling Visual Studio, try to reinstall Unity or just use another Script Editor.
edit: Just to inform, the version of Unity I was using was 2021.2.8f1. But I don't know if it matters since the bug didn't seem to depend on the Unity version.
I managed to fix the issue by installing Visual Studio 2022

How to setup Visual Studio for existing Unity project?

I have cloned an existing Unity project from git on a new machine, and the source does not include *.sln or *.csproj.
I have also downloaded Visual Studio from Unity Hub, but the editor doesn't work with Unity:
VS doesn't recognize Unity components
Unity doesn't update VS project (new scripts not recognized in VS)
I have selected VS as external tool for Unity, as shown here:
I also installed anything VS suggests (Mono, and a few plugins, etc). What's still missing?
The VS version is 7.7.4 and Unity is 2019.02
Problem fixed when I happened to re-open the project inside Unity:
Asset > Open C# Project
References:
Autocompletion not working in Visual studio
https://answers.unity.com/questions/1451377/autocomplete-in-visual-studio-wont-work-please-hel.html

Unity solution not compatible with visual studio

Since updating to the most recent version of Unity 5.4.0f3, whenever I doubleclick on a script, it launches both Visual Studio and Monodevelop, but I get an error saying that the this version of VS (Community 2015) is unable to open my project. Monodevelop displays it's own, somewhat less clear error message. Please see the screen shots below.
I can still manually open my script using Visual Studio's file menu, but the intellisense code completion no longer works. Anyone know how to fix this? I have Visual Studio's Tools for Unity installed.
I was having similar issues when doing a clean download of an existing Unity project onto a fresh install of Visual Studio Community 2019.
In the end the issue for me was that, although the correct version of VS Tools for Unity was installed, it was 'Disabled' by default in VS's Manage Extensions dialog (Extensions -> Manage Extensions). Just had to click 'Enable', restart Visual Studio, and all worked as expected again.
Turns out it was an issue with my existing install of Visual Studio Tools for Unity (VSTU).
I found a thread where users had experienced similar problems due to an unsupported version of VSTU running on Unity5.2 and beyond. Unity 5.2+ requires VSTU 2.1 or later for VS to work correctly with Unity, more information for anyone interested is available in the documentation here.
I had VSTU 2.3 installed, but removing and reinstalling VSTU resolved the issue, so there must have been a problem with my install. If anyone else has this or a similar issue you can download the latest installer for VSTU here. Thanks to all who chimed in your responses helped me look in the right place!
Please try following steps:
Delete old *.csproj and *.sln files on project's root folder
Check "Edit > Preferences > External Tools" and make sure you've selected "Visual Studio"
Re-open solution by "Assets > Open C# Project" menu
For me it was enough to right click the solution in Solution Explorer and run "Resolve errors".
I will complete what is said above. I experienced this issue today and it took me a while. In my case it was relative to a new install of the Unity Editor.
For some unknown reason the unity tool used on VS (intellisense) was uninstalled. I had to reinstall this : open Visual Studio Installer, select your project and reach the Gaming section where reside the tool for Unity.
The extension "Visual Studio 2019 Tools for Unity" seems no longer available for download via the extension manager. Luckily I recalled that I saw some game development features in the Visual Studio installer, so I picked that one:
It works for VS 2019 (16.11.11) and VS 2022 (17.2.0 Preview 1).

Visual Studio won't load my VSIX package

I'm trying to create my own VSIX package using the Project template. But when I actually launch it, it doesn't appear to be loading anything. That is, when running the project, it opens up another copy of visual studio, but it doesn't actually load up my plugin. I've compared my plugin to the other sample templates, and I just don't see anything wrong. It seems like it should be pretty straightforward. Are there any other steps besides creating the project that I have to do?
Are you using the visual studio experimental instance for debugging? You can enable this in the Project properties (right click your project and choose properties). Go to the 'Debug' tab and add the following line to 'Command line arguments': /rootsuffix Exp
More information about the experimental instance can be found on msdn.
I spent an entire day trying to reset Visual Studio (2015 Community Edition) by unloading features, deleting the cache directory, using the install to repair -- all with no success.
I finally uninstalled Visual Studio with success. When I initially installed Visual Studio, I had packages errors, like Python, that failed to load, but my Test Explorer worked beautifully. The test Explorer package stopped working in time. After re-installation, everything worked without any package load errors. Also, pay attention to the xml error files, because mine produced exceptions thrown by the package. (The xml error file is reported in the error dialog when Visual Studio informs the package failed to load.

Categories

Resources