Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio loses ability to attach to Unity, why?

I'm using Visual Studio with Unity. In general in VS I can simply click "Attach to Unity" and it will build the solution and indeed attach to Unity.

Sometimes, however, a project loses the "ability" to do so, what means that suddenly clicking the button will only build the solution and not attach to Unity.

I really would like to know what's happening there as I'm not aware of doing anything that could result in such a behaviour.
There are some parameters that might have an effect:

  • it happens only for some Unity projects: a project is either "infected" or it happens never (on my watch)
  • if it starts happening it will always happen until I reboot the PC (closing VS and Unity is not enough)
like image 294
Benjamin Zach Avatar asked Mar 25 '19 11:03

Benjamin Zach


People also ask

Why is Visual Studio not working with Unity?

Check that Visual Studio is set as your external script editor in Unity using Edit / Preferences / External Tools . Depending on your Unity version: Check that the Visual Studio plugin is installed in Unity. Help / About should display a message like Microsoft Visual Studio Tools for Unity is enabled at the bottom.

How do I associate Visual Studio with Unity?

In Visual Studio for Mac, on the top menu, choose Run > Attach to Process. In the Attach to Process dialog, select Unity Debugger option in the Debugger drop-down menu at the bottom. Select a Unity instance from the list and click the Attach button.

Is Visual Studio compatible with Unity?

Unity has built-in support for opening scripts in Visual Studio Code as an external script editor on Windows and macOS. Unity will detect when Visual Studio Code is selected as an external script editor and pass the correct arguments to it when opening scripts from Unity. Unity will also set up a default .

Why is the attach unity debugger not showing up in Visual Studio?

Here's how i fixed it. The Attach Unity Debugger will not show up unless you have installed the "Game Development with Unity" addon by going to youre menu item Tools / Get Tools and Features. From the Visual Studio Installer under workloads you'll see the option to turn on 'Game Development with Unity'.

How to build a solution in Visual Studio with unity?

I'm using Visual Studio with Unity. In general in VS I can simply click "Attach to Unity" and it will build the solution and indeed attach to Unity. Sometimes, however, a project loses the "ability" to do so, what means that suddenly clicking the button will only build the solution and not attach to Unity.

Is it possible to build a game from unity without errors?

I can build the game from Unity without errors, build the entire solution in Visual Studio without errors, but when I try to attach, I get "The operation could not be completed. Unspecified error". This is with Unity 2018.2.0f2, Visual Studio 2017 v15.7.5, and VSTU v3.7.0.1.

How does Visual Studio Tools for unity use DLLs?

If you are targeting the legacy runtime, Visual Studio Tools for Unity will use information from the DLL and PDB to create a DLL.MDB file, which is the debug symbol format used by the legacy Unity scripting engine.


2 Answers

For me (Unity 2020.x and VS19) this happens quite often. Simply close VS and in Unity > Edit > Preferences > External Tools

Click on "Regenerate project files" (you don't need to check anything else, just click the button)

Start VS again, and it should work as normal.

like image 94
Delta Avatar answered Oct 01 '22 01:10

Delta


For me "Attach to Unity" disappeared from the toolbar.

enter image description here

But I still have a button in Debug -> Attach Unity Debugger

enter image description here

Hope it will help someone.

Visual Studio Community 2019 16.7

Unity 2020.1.2f1

like image 36
hiichaki Avatar answered Oct 01 '22 03:10

hiichaki