Search Unity

Unity3d 2020.2.0b7 cannot attach visual studio debugger.

Discussion in '2020.2 Beta' started by koirat, Oct 22, 2020.

  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    Unity3d 2020.2.0b7
    When I press Attach in Visual Studio the small windows popup with title "Select Unity Instance" unfortunately it is empty making it impossible to debug.

    This started after upgrade from 2020.1, previously was working fine.
     
    claudiubarsan likes this.
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,492
     
  3. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    @koirat

    Did you solve this issue? If not, I'd love to help resolve it.
     
  4. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    Partially:

    I'm using:
    unity3d 2020.2.0b7.3288
    VS Community 2017 15.9.18

    I have just realized that when I run Unity3d as administrator than I can attach debugger.

    Is this related to firewall ? Should I open some ports, and what ports are needed ?
     
  5. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    It's possible, the debugger is a tcp connection IIRC.

    You shouldn't need to do anything explicitly, unless there was a rule created in the past - possibly by mistake. I would check your Windows Firewall settings and look for any rules for Visual Studio Tools for Unity or Unity in general and see if anything is blocked/denied.

    Also, I recommend updating to Visual Studio 2019 for the most up to date improvements on the Unity experience in VS. VS 2019 can be installed along with 2017, so you can keep both if you prefer.
     
  6. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    It looks like I was prematurely happy since it attached once.
    But right now even when I run as administrator I still cannot attach.
     
  7. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    Ok, at least things are consistent. :)

    Let me know if you find any firewall rules defined. Additionally, it's worth checking if the Unity Editor is correctly setup to use Visual Studio.

    Make sure that the Visual Studio Editor package (use the Package Manager) is up to date with version 2.0.3 and also check Preferences > External Tools and verify that Visual Studio is selected as the external editor. In that menu, you can also click the regenerate project files button.
     
  8. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    Already had all Visual Studio related packages updated.
    Also when I double click script in unity3d it opens in VS so it looks like it is set properly.
     
  9. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    @koirat

    Did you confirm if the package was up-to-date and that it's explicitly set as the External Tool? There are other ways the script could open in VS even when not set.

    You shouldn't see a dialog to select Unity instances when you click the Attach to Unity button in the VS toolbar. That dialog would only appear if you select the Debug > Attach Unity Debugger menu item.
     
  10. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    After regenerating the project I was able to debug.
    But then I got the unity crash and when going back to project I was not able to attach even after regenerating it for the second time.

    So I guess this has nothing to do with firewall.

    VS is set es external editor and Visual Studio Editor v2.0.3 enabled.
    "Embeded packagess" checked
    "Local packages" checked
    Rest is unchecked.
     
  11. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    Hm, the Unity crash is odd.

    Are you able to try a different Unity version? The 2020.2b could be related.
     
  12. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    Yea. A total shock. It took me completely of guard. ;)
    Upgraded unity to 2020.2.9b was able to debug once later when I have tried again this little dialog box has shown again.

    Is there a way I can get the logs for attaching debugger (Unity or VS logs). It might give us some hints.
     
  13. 1pietras

    1pietras

    Joined:
    Jan 21, 2014
    Posts:
    1
    I am still on 2020.2 alpha, but this might help you.
    There is a Debug -> Attach Unity Debugger option in Visual Studio, there you should have an option to attach to Unity.
    I have similar issue and I am using that workaround.
    Sometimes I have two instances of unity (???), but you can find correct one by checking if breakpoints are active
     
    hawaiian_lasagne likes this.
  14. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    859
    Tried it. Did not work .
     
  15. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,111
    I could add here that I can attach debugger to the Unity editor fine during editor mode, but as soon as I play the game, it detaches itself. Is this notmal behaviour? Cause, it is really annoying to try and debug the initial loading part of the game because of this obvious reason.
     
  16. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    175
    Still happens in the last release, Unity 2020.2. Using VS2017 too. Sometimes it works, sometimes it does not. I couldn't find the pattern. This never happened with Unity 2019.4, as soon as I upgraded the project problems arised. I don't want to do off-topic but the other problem I've observed is that after executing the game a pair of times Unity starts using 30% of my CPU without an apparent reason (without playing, just idle), this happened with Unity 2020.1 too. The only solution is to restart the editor. I've seen also that there were 2 instances of the Unity editor in the Task manager (and I've seen even 3 instances of the UnityHub). Many rare things are happening.
     
  17. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    @ThundThund

    If you haven't already, please use the Help > Send Feedback > Report a Problem menu in Visual Studio to log an issue. That will help our team track the problem and follow up.
     
  18. ThundThund

    ThundThund

    Joined:
    Feb 7, 2017
    Posts:
    175
    Hi, it does not seem to be a problem in VS, in my case it just does not know to which Unity instance to connect, like when you have several Unity editors open, but in this case there are not several but just one.
     
  19. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    @ThundThund,

    No worries, it's best to file an issue anyway with as much information as you can provide.

    It would also be worth downloading and trying VS 2019 and report if that has the same behavior. Thanks!
     
  20. Sanctus2099

    Sanctus2099

    Joined:
    Dec 11, 2013
    Posts:
    71
    I seem to have the same issue after upgrading to Unity 2020.2 from 2019.x. Sometimes it works, sometimes it doesn't. The solution seems to be to restart Unity. I've read that there's a bug in vs2017 which won't display the available instances when there's more of them. I'm guessing here that somehow vs registers the unity instance twice (both edit and play mode?) and thus tries to show the 2 instances which triggers the other bug.

    I would install visual studio 2019 but I also use it for the work I do for my employer and I already have both 2015 and 2017. I'm afraid this is going to somehow mess up my ecosystem and I'll have to spend a few days fixing it.
     
  21. Quantexlda

    Quantexlda

    Joined:
    Nov 7, 2017
    Posts:
    5
    Same issue for me since upgrade from Unity 2017 to 2020.2.1 - with Visual Studio 2017- upgrade to Visual Studio 2019 - same.
    An issue was existing into Unity 2017 and Visual Studio 2017 - When debugging pluggin on C# - it was needed to "regenerate all" the C# project then refresh the Asset to have a link working on debug for Pluggin, and some times restart Unity3D at All. This sound to the be case all the times since new Unity Version for both Pluggins and Unity C# projects. So it could be a bug on both side - Unity + VS, where the last Unity Version generate a locking point.

    Since Unity 2020.2, after first restart of Unity - requesting to attach to unity seem to work (Visual Studio bottom bar switch to red), Unity request if we need to "Enable Debugging for this project or All" (that is new - new = bug?) then Unity switch to status 'Not Answering" into task manager - until we "stop debugging" or wait for a while (about 2-3 minutes).
    If we retry without restarting Unity - Unity no longer suggest to switch to enable debug and stay "Not Answering" - the only solution is to "Stop Debugging" then restart Unity. And then stay at a point where it still does not work. So Retry does not work.

    Rebooting the computer - same issue

    An other try is re-install and downgrade to 2020.1.17. A first debug process work, then after ending first session, same issue as on 2020.2.1 and then does not work

    Downgrade to 2020.1.0... debug seem to work for multi sessions. Will see and wait for Unity correction on last version...
    UPDATE: 2020.1.0 allow Unity3D scripts to be debug, but no longer C# plugins...
     
    Last edited: Jan 23, 2021
  22. Quantexlda

    Quantexlda

    Joined:
    Nov 7, 2017
    Posts:
    5
    RTFM and re-doing the configuration seem to solved one side of the issue for me on following case:
    Using Visual Studio Tools for Unity | Microsoft Docs

    It seems that if you have DLL first-partie Mono Compatible (.NET 3.5) you can no longer use pdb2mdb tool from Microsoft and you have to switch to 4.5+ and "Portable" debuging. So that change allow me to work with the 2020.2.1 and debug the DLL First-Partie on real time.

    So that do not solve at all the issue with Unity3D project. BUT a strange thing is that starting to debug with the DLL, then stop it, then starting the Unity3D debug allow to make it working. Strange process but it seem that it allow to open doors/init process and then allow to work.

    Message sent to LeonhardP and ticket open at Microsoft.
     
  23. Sanctus2099

    Sanctus2099

    Joined:
    Dec 11, 2013
    Posts:
    71
    Can we please get an answer here? It's ridiculous to have to restart Unity all the time because VS won't attach to it, especially when you noticed a bug and want to see what's going on. Since this was working fine before and the only updated thing was Unity one can't help but figure out the problem is not with Visual Studio.

    I'm so tired of constantly defending Unity when other criticize my choice of using it when I had various issues with every single update except one(2019.1.14). I made it a point to subscribe to the Plus license just to show you support even though I have yet to release a commercial project, but with regressions all over the place I just don't know if you deserve it anymore.
     
  24. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    114
    @Sanctus2099

    I'd be more than happy to work directly with you and resolve this quickly. If you're willing to do that, please message me on here an I'll work with you setup a time to do that.

    Otherwise, the best way to get support for troubleshooting this and document the issue is to use the Help > Submit Feedback > Report a Problem menu in Visual Studio if you suspect it's a VS issue. That will guide you through filing an issue that our team can get version information and automatic log data from.
     
  25. Sanctus2099

    Sanctus2099

    Joined:
    Dec 11, 2013
    Posts:
    71
    @John_MSFT I would just like to point out here that I did write you in private, trying to get to the bottom of it, and there was no answer on your part.
     
unityunity