Visual studio can't attach to unity editor.

When debugging I would like to attach to Unity and cycle through my breakpoints, however the “Attach to unity” button is replaced with “Start” and I can’t seem to fix this.

I’ve gone so far as to delete my personal VS and old Unity to install the latest bundle where Unity comes with VS 2015 community as the requested feature should be available out of the box, but to no avail.
What can I do to fix this? It would mean a ton!

Thanks in advance.

Those didn’t work for me so I found answer in forums. I am using Visual Studio 2017 so for some reason it wasn’t already installed for me. To install Tools for Unity in VS:

Close Unity just to be sure nothing goes wrong.
in Visual studio → Tools → Tools and Features…

New window pops up. Scroll down on tab “Workloads” to section “Mobile & Gaming” and you find “Game development with Unity”. Check the checkmark and click “Modify” in the bottom right corner of that window.

This will then ask about VS processes running, click “continue” and it closes your VS-windows and continues installing the Tool you need. after it’s done your Visual studio editor comes back.

Close VS, Open Unity and double click script to open it in VS(If you have it setup as editor in Unity preferences[Edit->Preferences->External Tools->External Script Editor → set it to Visual Studio]).

Now you should see “Attach to Unity”.

To solve this issue go to C ->Program Files->Unity->Editor and rename the unity exe file to "Unity.exe " remove the version extension if any

What worked for me is to update visual studio.
Go to Tools>Get Tools And Features…>Modify>Update

All done!

This happens to me when reorganizing files or otherwise refactoring (using Unity 2020.3.30f1 + VS 2019). The only thing that works consistently for me is:

  1. Close Visual Studio
  2. Delete the .csproj file in the root of the project directory
  3. In Unity, go to Edit > Preferences > External Tools > Generate .csproj files for
  4. Select the items you’d like to include in the project file generation
  5. Click the Regenerate Project Files button

I had a similar issue. Installing the latest version of VS tools for unity fixed that.

These worked for me -

Debugging Unity on a Mac with Visual Studio (steps may work for a PC too)

---------------------------------------- ----------

Setup:

a. In Unity make sure VS is set in Unity->Preferences->External Tools - External Script Editor set to VS

b. In VS - Install the latest Unity Tools for Visual Studio (Game Development with Unity).

c. Click a script in Unity to Open VS


Steps:

------
  1. In Unity goto Unity->Preferences->General - set Code Optimization on Startup to “Debug”

  2. In Unity goto File->Build Settings

  3. Change Run in Xcode as to Release or Debug (the change resets it in VS)

  4. You should see the PLAY button in VS with “Attach to Unity” as one of the options


  1. (If that doesn’t work, do this:) 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)

  2. Start VS again by clicking a script should be able to see the “Attach to Unity” option


Alternative to Attach Button on PC

1. In VS - goto Debug->Attach Unity Debugger-> ...select the Unity Process running your project.

I founded one solution which might work for all cases. 1. Just start any version of VS separately from Unity. 2. Open solution file which is previously generated for project. 3. Open Unity, and double click on any script. It will be opened in VS and Attach will be there.

Note: I have project in Unity 5 and was working with VS 2017. Sln file is generated by VS 2017. And now on this way I can use VS 2019 and VS 2022 normaly.