Search Unity

Can't attach Unity to Visual Studio

Discussion in 'Code Editors & IDEs' started by DrDress, Sep 16, 2019.

  1. DrDress

    DrDress

    Joined:
    Sep 11, 2019
    Posts:
    30
    Ok I updated to VS 2019 I now I can select this:




    But now I get this option:


    I don't know what to do here. The "OK" button is greyed out :-(. Any help?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Can you select Evolution position?
     
  3. DrDress

    DrDress

    Joined:
    Sep 11, 2019
    Posts:
    30
    Aaah... yeah I might have tried that myself... Oh well it did the trick. Thanks alot!
     
    Antypodish likes this.
  4. DrDress

    DrDress

    Joined:
    Sep 11, 2019
    Posts:
    30
    Well actually it works a little odd. When I select Evolution it starts debugging, and when I start in Unity it will run the scripts and get stuck in the breakpoints as it should. But when I stop again the debugging also stops and I can edit the code again. But I then have to do all the same stuff again if I want to run in debugging mode again. That's pretty annoying. Isn't there a way to always start the debugger in VS when I run in Unity without a lot of manual stuff?
     
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Technically once you attach, it should stay attached.
    But as far I have experienced unfortunately, Latest Unity with VS is quite temperamental.
    Which version of Unity you are using?
     
  6. DrDress

    DrDress

    Joined:
    Sep 11, 2019
    Posts:
    30
    version 2019.2.0f1
     
  7. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    You should only need to press F5 (Or Start button) to attach to your Editor in your case.

    Using "Attach to Unity debugger" is useful when:
    - you want to debug a local or remote player
    - you have several editor instances running
    - you want to do orchestrated debugging, like debugging the editor and several players at the same time

    Seb
     
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Is not always true, since VS sometimes don't want to attach at all. Restarting both Unity and VS is best remedy in my case.
    However, I
    am not sure if that is more VS, or actually Python related, as I had been installing recently python and had some conflicts with VS version of python. Coincidentally I upgraded Unity to 2019 at the same period. And VS Unity attaching troubles become more often since then.

    Reinstalling VS didn't help.
     
  9. Gabe851

    Gabe851

    Joined:
    May 13, 2017
    Posts:
    32
    i fixed this by going to edit > preferences > and checking the bool next to 'Player Projects' under 'generate .csproj files for:' and clicking 'Regenerate project files' button. The other stuff did not work for me
     
  10. tingwen55555

    tingwen55555

    Joined:
    Mar 4, 2017
    Posts:
    2
    I have this problem sometimes. Try deleting the .sln file created in your project folder (where you see your assets and library..etc). It fixed it for me
     
  11. mastermemorex

    mastermemorex

    Joined:
    Nov 5, 2017
    Posts:
    6
    Try to delete de .csproj and .sln files. Unity will regenerate those files. That worked for me.
     
  12. nikix22

    nikix22

    Joined:
    Jan 16, 2015
    Posts:
    25
    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.
     
  13. desdinovait

    desdinovait

    Joined:
    Jan 3, 2020
    Posts:
    6
    Perfect solution, thanks