Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Unity3d 2020.2.0b7 cannot attach visual studio debugger.

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

Thread Status:
Not open for further replies.
  1. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,100
    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.
     
    NEOMORPH_STUDIO_SRL likes this.
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,143
     
  3. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @koirat

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

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,100
    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:
    118
    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:
    2,100
    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:
    118
    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:
    2,100
    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:
    118
    @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:
    2,100
    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:
    118
    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:
    2,100
    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
     
    pzn and hawaiian_lasagne like this.
  14. koirat

    koirat

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

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,522
    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. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    349
    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:
    118
    @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. AlexVillalba

    AlexVillalba

    Joined:
    Feb 7, 2017
    Posts:
    349
    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:
    118
    @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. Lorin_Atzberger

    Lorin_Atzberger

    Joined:
    Dec 11, 2013
    Posts:
    121
    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:
    7
    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:
    7
    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. Lorin_Atzberger

    Lorin_Atzberger

    Joined:
    Dec 11, 2013
    Posts:
    121
    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.
     
    PrimalCoder likes this.
  24. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @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. Lorin_Atzberger

    Lorin_Atzberger

    Joined:
    Dec 11, 2013
    Posts:
    121
    @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.
     
  26. kamicazer7

    kamicazer7

    Joined:
    Oct 27, 2012
    Posts:
    7
    Hey, just wanted to drop a workaround I found. Using Visual Studio 2017 and Unity 2020.3. I am facing the same issue, "Attach to Unity" will stop working at random.

    So, in order to be able to debug, I go to Debug->Attach Unity Debugger then select all instances present in the list (using CTRL+clicking each) and pressing ok. Doing this allowed me to debug most of the time. There are some times even that won't work and I have to reboot windows for it to start working again.

    Capture.PNG
     
  27. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    681
    @John_MSFT

    I just upgraded to the latest version of Visual Studio Community 16.11.2 and it broke Attach to Unity debugging. Clicking attach to debugging compiles code and then nothing happens. VS doesn't attach the debugger.

    Is Visual Studio Community 16.11.2 and Unity 2021.1.18f1 a known working configuration?

    I regenerated project files, confirmed firewall settings, and validated that I can connect to the debugger using VS Code. Also, the Visual Studio Editor package is Version 2.0.11 - July 08, 2021. Given that it worked right up until the point I upgraded, it seems like a bug.
     
  28. giuliboy

    giuliboy

    Joined:
    Aug 5, 2017
    Posts:
    1
    +1
    same as stonstad
     
  29. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    681
    The VS team had me uninstall VS2019 and reinstall it. I did this and it restored debugging functionality for two days. Today, it is failing again with:

    The operation could not be completed. Unspecified error

     
    Last edited: Feb 6, 2022
  30. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    681
    Is anyone finding consistent success with the Visual Studio Code IDE or JetBrains IDE? The last time I tried VS Code it failed to work for different seemingly random reasons. It could connect but breakpoints wouldn't fire. I'm loathe to install a new IDE but at this point I'm not sure I have an alternative.
     
  31. Lorin_Atzberger

    Lorin_Atzberger

    Joined:
    Dec 11, 2013
    Posts:
    121
    I used VSCode for a while and it was an overall horrible experience. It can attach well, the IDE is awesome but the Unity extension is unmaintained and functions poorly. For instance, if you're stopped in a breakpoint and want to add another breakpoint somewhere it will also trigger a continue. When looking at variable values lots of things don't show good results or it might even make the debugger hang. I tried fixing some of this stuff myself but that code is all a frontend of an ancient port of a port of a port of some repo that's advanced quite a bit meanwhile (MonoDebug if anyone is curious).

    Then I tried Rider. So far I've had no real issues with it. Debugging works well and it even has some nice custom Unity features like being able to examine all components in a game object, look at the hierarchy and the scene structure. Halfway through the trial I figured this is going to be my new IDE and I even got a 20% off the annual subscription on something I was going to buy anyway. During the trial I even reported a minor resharper bug (some false positive) and about a week later it was fixed. The only real issue I've seen so far, and it happened like 2 times, is that when the debugger is connected (not hanging in a breakpoint) Unity might get stuck in a "Application.Update" loop. Detaching the debugger does not help and I have to kill Unity and restart it. I have not seen this issue with other IDEs but it still sounds like a Unity issue, not a Rider one.
     
  32. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    681
    Thank you for the suggestions. I was contemplating Rider as a way to stay productive. Re: The Application.Update loop, I see it in Visual Studio too. Happened once when I renamed a file and I had to kill everything. Thanks again!
     
  33. PrimalCoder

    PrimalCoder

    Joined:
    Aug 12, 2014
    Posts:
    13
    This is the only thing that has worked for me, so I appreciate you posting it.
     
  34. intricatekill

    intricatekill

    Joined:
    Jan 4, 2021
    Posts:
    1
    Putting this here since this is the first result if you google "cannot debug unity 2020"
    I hit this issue on VS2017 latest, switched to VS2019 (I had to install unity dev tools since I usually use 2017 for Unity) and that fixed the issue for me.
     
    Ultroman likes this.
  35. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    681
    I occasionally retry this debugging workflow in Visual Studio to see if things are fixed but I have essentially given up. I recently retested and VS2022 still fails randomly with the "The operation could not be completed. Unspecified error" behavior. It's sad because VS can be a productive IDE when it works.
     
  36. dfernand

    dfernand

    Joined:
    Jun 21, 2014
    Posts:
    9
    I get this sometimes, happened today with Unity 2020.3.30f1 on Windows 10 running Visual Studio 2019 Pro. One thing that I was doing before this problem occurred with the 'attach to unity' button in visual studio is that I had two instances of Unity 2020.3.30f1 open so maybe it got in a muddle regarding which of the two to connect to. I killed one unity instance, both unity instances and MS Visual studio 2019 msdev and restarted one of each only and tried again and still the same. So I dunno if it's McAfee suddenly blocking on the ports for attach process or whether somewhere it still thinks MS Studio is already attached and the connection isn't resetting etc. I dunno which process to kill via Task Manager to fix this. Restarting Windows 10 and rebooting fixes this problem for me.
     
  37. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    upload_2022-6-11_13-14-6.png

    This issue began sort of out no where for me yesterday, when Visual Studio 2019 stopped connecting to Unity 2019.4.3 after being relatively successful for the last month. Once in awhile I would get "The operation could not be completed. Unspecified error" and no further details, but restarting VS would seem to work.

    However now it outright no longer works. In fact for half of yesterday I didn't even get the error, the debugger would just quietly fail and disconnect immediately.

    Things I have tried (that have NOT worked)
    - Tried using Attach Unity Debugger instead
    - Deleting all the solution & project files and rebuilding
    - Regenerating the project files via Unity's Preferences -> External Tools
    - Opening the solution via the Assets -> Open C# Project
    - Deleting all of my Unity Library/obj/log/temp folders and rebuilding the entire project
    - Updating VS & the Unity Visual Studio Editor support package to absolute latest
    - Uninstalling the Unity Visual Studio Editor support package and reinstalling
    - Uninstalling the Unity Game Development component from Visual Studio's installation, and reinstalling it
    - Unselecting and reselecting the External Editor as Visual Studio, including just manually pointing it to devenv.exe
    - Making sure the Windows Firewall is not blocking anything, and confirmed with TCPView if any conflicting ports were already in use
    - Attempted deleting MEF ComponentModelCache from %localappdata%\Microsoft\VisualStudio\[version]

    Alas. NOTHING. The last ditch effort thing I can try is uninstalling and reinstalling Visual Studio. (I saw someone claiming they had to reinstall WINDOWS, which is where I'm going to draw the line )

    After a bunch of quitting every possible open program I can on my PC and closing and relaunching, I did at least manage to get the "The operation could not be completed. Unspecified error" to begin appearing again, but still absolutely no progress on getting it to successfully attach.

    If I create a brand new Unity empty project and attempt to attach the debugger to it, I have a 50/50 success rate, which is still higher than my current 0% with the project I NEED it desperately for. So what does all this mean? I have no idea! Without a real error message here I'm going crazy trying to guess what this thing want.

    Additionally, Submitting Feedback via Visual Studio no longer works, it appears. Not for 2019 anyways, the website it launches just states that Visual Studio was disconnected (and then also says 2019 is no longer being supported, so in MS terms that probably means Feedback Submission is either broken or goes straight into the toilet roll feed)

    I sent @John_MSFT a direct message, but then realized it would be better to post this on public in case someone else is trying to Google a possible fix for this. John hasn't been active for a year in this thread so I'm concerned he may no longer be available.

    @LeonhardP is this a bug that should be submitted for Unity or Visual Studio?
     
    Last edited: Jun 13, 2022
  38. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    681
    @John_MSFT, this issue has been open for over a year. Did you guys ever identify the cause and provide a fix?
     
    Gametyme likes this.
  39. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    After a random reboot, my debugger began working again. I'm guessing I just got a lucky roll of the dice this time, so I've just been keeping Unity/VS open as long as possible since then.

    I still have no leads as to what the cause is, but ultimately when it happens again I am going to reinvestigate the ports (a 3rd time), as I do know the port # that the integration picks is semi-random upon launch.
     
  40. SaeedPrez

    SaeedPrez

    Joined:
    May 10, 2017
    Posts:
    6
    If anyone is still having this issue, try this..

    For me if I open the project from Unity, I cannot attach the debugger.
    However, if I go to the folder and double click the .sln file, it attaches without problem.

    Edit:
    After more testing, the above solution stopped working.
    What has now worked for a couple of days is:
    1. Go to Edit > Preferences > External Tools
    2. From the checkboxes select only Player projects
    3. Click Regenerate project files
    This allows me to open the project from inside Unity and attach the debugger without any problems.
     
    Last edited: Jul 8, 2022
  41. mdalecki

    mdalecki

    Joined:
    Jan 16, 2018
    Posts:
    1
    For me it works to switch to Release mode and switch back to Debug. After that it works like a charm :). You can switch mode in the right bottom corner: upload_2024-5-26_0-23-26.png
     
    codered likes this.
Thread Status:
Not open for further replies.