I need to debug my scripts, but if I click "Attach to Unity" or "Attach to Unity and Play" then the button is just grayed out and after a few seconds it is clickable again, but nothing happens.

Attach to Unity and Play (green arrow)

Attach to Unity and Play (gray arrow)

Attach to Unity and Play (green arrow)

I already tried to restart visual studio, but it did not helped.

I restarted unity, but this brings no success too.

  • 2
    \$\begingroup\$ This sounds like a bug you might be able to get better help with from the Unity support site. \$\endgroup\$ – DMGregory Nov 5 '17 at 13:07
  • \$\begingroup\$ Does the problem persist if you launch visual studio from inside Unity? (As in, double clicking on a script inside unity and launching it that way) \$\endgroup\$ – John Hamilton Nov 6 '17 at 5:46
  • \$\begingroup\$ @JohnHamilton, yes. I always start it like this. \$\endgroup\$ – Black Nov 6 '17 at 9:38
  • \$\begingroup\$ Try Debug > Attach to unity debugger \$\endgroup\$ – Alakanu Nov 7 '17 at 14:13

Answering comments (still can't comment):

I only had to do it for one script.

If that didn't work, you can try "Assets -> Reimport All", since it's supposed to fix corruptions in your project. Notice Unity warning saying it can that several hours.

Original answer:

I had a similar problem this morning, found a lot of solutions, but the only one that worked for me was to click on the file, go to "Debug-> (Project) Properties > Compile Action", select "None" and then select "Compile" again.

That seems like a bug but a have no ideia why that worked.

Properties at Visual Studio

  • \$\begingroup\$ Do I have to do this for every single script? \$\endgroup\$ – Black Nov 6 '17 at 15:19
  • \$\begingroup\$ I just tried it, and it does not work. \$\endgroup\$ – Black Nov 6 '17 at 19:40
  • \$\begingroup\$ Just tried this, and it worked for me. Thank you! \$\endgroup\$ – Dayman75 Mar 18 at 15:34

Today everything just works fine. Thats so weird. Yesterday I had no chance but today everything is perfectly fine. What is the reason? Next time whenever I have a problem with software, I will just turn my computer off for some minutes and then turn it on again, sounds stupid? I know, but apparently it works.

  • 1
    \$\begingroup\$ When in doubt (the state where you've tried everything and it just doesn't seem to work), just turn it off and on again (the whole system I mean). It might just fix some stuff that you didn't even know were being a problem. \$\endgroup\$ – John Hamilton Nov 6 '17 at 10:17
  • \$\begingroup\$ Now the problem appeared again, after I set a breakpoint in a set method and then pressed on "Attach to Unity and Play"... \$\endgroup\$ – Black Nov 6 '17 at 12:21
  • \$\begingroup\$ Maybe this is related to the unity crash which was intendently forced by me because unity was freezing from an infinite loop? hm \$\endgroup\$ – Black Nov 6 '17 at 13:28
  • 1
    \$\begingroup\$ If you forced Unity to close and didn't close Visual Studio, it usually breaks the connection and can't get it back up. It's best to include some stuff against infinite loops in all your codes (i.e. don't check for some value to become true and halt your code, make a function to wait for it etc.) \$\endgroup\$ – John Hamilton Nov 6 '17 at 14:20
  • 1
    \$\begingroup\$ Another day passed, I started my computer and tried to debug, it does not work... this must be a major bug. \$\endgroup\$ – Black Nov 7 '17 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.