Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Can't Attach Visual Studio to iOS device

Discussion in 'Experimental Scripting Previews' started by Slawb, Nov 6, 2018.

  1. Slawb

    Slawb

    Joined:
    Nov 12, 2015
    Posts:
    8
    Hello everyone,
    I've got a problem with iOS managed debugging in VS Community for Mac.
    I'm using Unity 2018.2.6f1 and Visual Studio Community for Mac 7.4.3 (build 10).
    I've checked all the settings for building my app and debugging, i can build without any problems and on startup the application on the iPhone shows a pop up saying: "Debug - You can attach a managed debugger now if you want".
    Schermata 2018-11-06 alle 14.35.34.png
    But on the VS side, I can't select anything except "Unity Editor" as debug target.
    I could not find a way to attach another target.
    Does someone have any tips?
    Thank you.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Try to use the Run > Attach to Process menu, and make sure the "Debugger:" option at the bottom of the dialog is set to "Unity Debugger".

    Also, if the iOS device is a phone, make sure the Wifi connection is the only active connection. You can do this by putting the phone in airplane mode, then enabling Wifi.
     
  3. Slawb

    Slawb

    Joined:
    Nov 12, 2015
    Posts:
    8
    Wow, thanks!
    You're a life saver, i didn't know that setting was there.
    I would have never got it without your help.
    Thanks alot!
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  5. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    78
    I could attach the debugger, but it doesn't break on breakpoints.
    macOS, Unity 2019.2.18
    iOS 12, iPhone 5
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Are you trying to break in script code from the Unity project (e.g. in Assembly-CSharp.dll)? Or are you trying to break in code in a pre-compiled assembly in the project?
     
  7. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    78
    A Unity script. Not a pre-compiled assembly.
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Ok, thanks for the information. Can you submit this project with a bug report? It sounds like something we should investigate then.
     
  9. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    @JoshPeterson As a quick aside, for us connecting VSCode to the editor or to an iOS device has been a no go for years - the debuggers don't connect, or they connect and disconnect immediately, or they beachball, or if they do magically connect they either don't break, or if they break they don't step in or step out correctly. I've filed bugs in the past but nothing seems to come of it. Prior to that, old MonoDevelop connecting to old Unity was an instant beachball on Mac as well, so Debug.Log has been my trusty friend for about 10 years.

    I haven't checked the latest Unity so I'd be pleasantly surprised if it's working, but the last time I checked an iOS debug connection to an IL2CPP project it instantly failed (yes, the phone cellular was turned off, etc). In addition, the VSCode v1.1.4 verified package is currently broken on Mac (bug reported). I don't know how your devs using Macs don't hit the same problems everyone else seems to hit. I think the VSCode stuff is technically unsupported by Unity so fair enough it might break a bit, but as a verified package it breaks in a fresh project.
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I can't speak to VSCode, as I've not used it myself, and I don't believe it is officially supported by Unity. With 2018.4, 2019.2, 2019.3, and 2020.1 Unity versions though, iOS debugging with VS for Mac and JetBrains Rider work internally (modulo bugs).
     
  11. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    hi Josh, yep that's right, the VSCode debugger extension says it's unsupported in the extension description / docs which is a shame because VSCode as a C# and general purpose editor is great. I've not used Rider but always heard good things (tested their pre-release version for a few weeks but not tried it since). I'll reinstall Visual Studio Code for Mac and test an iOS connection/debug in 2019.2 sometime.

    No doubt it's hard trying to keep all these tools working and improving as the .Net flavours and IL2CPP change under the hood. Thanks for your hard work and for being active in the forums too. Looking forward to seeing if and when all the new C#/.Net stuff makes it over the Unity fence.
     
  12. JackGrayBrain

    JackGrayBrain

    Joined:
    Aug 24, 2018
    Posts:
    7
    I am attempting to debug a Unity (2018.4) project running on an up-to-date iPad from the latest Mac Visual Studio. I am able to see, from the Mac, the iPad open port that the Xcode debugger reports (Multi-casting "[IP] 192.168.1.9 [Port] 55000 ...snip...) but when I start debugging and try to attach to the process I see only Unity Editor in the attachment options in VS. upload_2020-2-20_14-35-22.png

    My build settings are:
    upload_2020-2-20_14-50-22.png

    The profiler pops up but nothing ever appears in it even when I turn off script debugging.

    Any ideas on how to get beyond these blocker would be greatly appreciated.

    I am able to attach to an Android device running the same Unity source, though.
     
    Last edited: Feb 20, 2020
  13. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    393
    @JackGrayBrain
    You have to check 'Symlink Unity Libraries'. Please check my blog post.
     
    roointan and lifestreamXR like this.
  14. ninadpradhan

    ninadpradhan

    Joined:
    May 9, 2018
    Posts:
    9
    Exact same issue, it’s says "This request is not supported by the protocol version implemented by the debuggee” when the break point hits... when is this going to be fixed?
     
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Which IDE are you using to attached to the Unity player?
     
  16. felixmann

    felixmann

    Joined:
    Feb 16, 2017
    Posts:
    11
    Like JackGrayBrain I'm not seeing my IPad in the Mac Visual Studio dropdown:

    Screen Shot 2020-05-21 at 5.08.04 PM.png

    My Unity build settings:

    Screen Shot 2020-05-21 at 5.09.54 PM.png

    My Unity version is: 2019.2.21f1

    My Visual Studio Version is: 8.6 (build 4520)

    When I select "Build and run" from Unity and have my IPad plugged in the app launches and the profiler connects.

    I've tried unplugging the usb cable and the airplane mode wifi trick.

    Any ideas?
     
    PGI2017 likes this.
  17. felixmann

    felixmann

    Joined:
    Feb 16, 2017
    Posts:
    11
    Looks like I was missing a key step. From Visual Studio instead of the dropdown I was using (pic in previous comment) I needed to:

    Run > Attach to Process > Select my IPad

    Works like a charm. My IPad is not plugged in to my Mac.
     
    vaishakh_r likes this.
  18. manpreetsains

    manpreetsains

    Joined:
    Oct 19, 2019
    Posts:
    1
    Hello i am also facing the same issue, cannot see my ios device in the attach the process. What can be the issue?

    Felixmann can you please guide me how to resolve this issue.
     

    Attached Files:

    AM-Dev, vaishakh_r and makaka-org like this.
  19. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,026
    Unity docs say that need to disable firewall on router, but it doesn't help.
     
  20. JeromeGodboutAmotus

    JeromeGodboutAmotus

    Joined:
    Apr 24, 2020
    Posts:
    40
    I still wonder why do I have to put my iPhone into airplane mode to debug it?!? Every time I forget about this and I cannot debug it (I do not do Unity3D as full time). This is a unity thing that is super annoying. Xamarin VS, xCode doesn't need this. Any plan on removing this particular needs one day?
     
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    The debugger agent code which runs on the iPhone must bind to a network interface. That network interface must be on the same local network as the machine running the IDE. When I last looked at this, there was no API on iOS to determine if that interface is on WiFi or cellular, so the code was unable to find the right network interface (the WiFi one).

    I'll check with the mobile team to see if this has changed though.
     
  22. vasildx

    vasildx

    Joined:
    Jun 6, 2018
    Posts:
    2
    Hello! I am also facing into same issue after upgrading iOS to 16.1. Everything was working fine before iOS upgrade to 16.1 version on both iPad Pro and iPhone XS max. On old iPad Air 1 with iOS 12 script debugging works well. Exactly problem is in iOS 16.1, maybe security things that actually prevent the managed debugger from working.
    I used latest Unity 2022.1.21f1 on Mac OS Ventura (13.0)
    Please, if anyone faced how to solve this problem on iOS 16, let me know.
    Thanks in advance!
     
    crs117 likes this.
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This is the first that we've heard about this issue. Can you submit a bug report?

    https://unity3d.com/unity/qa/bug-reporting
     
  24. cgaisc

    cgaisc

    Joined:
    Nov 28, 2022
    Posts:
    5
    I have the same issue. iPad with now iOS 16.1.1 is not detected by Visual Studio, but has also not been detected with iOS 16.0
    The iPhone with iOS 14.4 is detected.
    I also posted that problem on stackoverflow: https://stackoverflow.com/q/74728292/6796677

    Can you please add a link to the Bug-Page as soon as the bug report has been created?
     
    crs117 and makaka-org like this.
  25. crs117

    crs117

    Joined:
    Oct 24, 2016
    Posts:
    4
    @JoshPeterson I too seem to be having issues trying to attach my iPhone 13 to my M1 max. I have checked all the checkboxes for debugging but the iPhone does not show up in the Attach to Process debugger. I can debug unity fine in play mode but as reported by @vasildx and @cgaisc with the latest versions of MacOS and IOs the i device does not show up plugged in to the computer or not.

    Also when I was accessing camera's via web browsers (for barcode scanning), android and windows tablets and phones would have descriptive indicators returned when querying for camera. iPhones and iPads returned non descriptive hashes but would always return them in the same order. Using this allowed me to query the system and enumerate camera's by OS. It would seem as though when querying for network interfaces in IOS the same hold's true. I guess it is somewhat compounded by the fact that on IOS not all devices have cellular and I believe bluetooth would also show up as a network interface which means you really may have no idea. I would assume the first returned interface would be Wifi by default but if you have to turn off your cell radio I guess not.
     
    IMD likes this.
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Are you using the airplane mode with WiFi enabled? It seems like you might already be doing that, but I wanted to confirm. Also, which version of Unity are you using?
     
  27. GAMEDIA_Justin

    GAMEDIA_Justin

    Joined:
    Mar 29, 2017
    Posts:
    19
    We are having the same issue with our Mac mini M1 2020 on Ventura 13.1 with Unity 2021.3.17f1 and Visual Studio for Mac 17.4.4. We can't attach to our iPhone X with iOS 16.2 and our 5th generation iPad running iPadOS 16.3.

    Airplane mode and Wi-Fi are both enabled.
     
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can you submit a bug report for this issue? As far as I know this should work, but maybe there is something in this combination of tools that is a problem.

    https://unity.com/releases/editor/qa/bug-reporting
     
    whitedoger likes this.
  29. munchcreative

    munchcreative

    Joined:
    Mar 6, 2023
    Posts:
    1
    Can confirm that this isn't working with iOS 16.3.1 (iphone 14 pro), Visual Studio for Mac 17.5 (build 1802), Unity 2021.3.10f1. iPhone 14 doesn't show up for Attach To Process.

    When I opened the game in TestFlight on an old iphone 6s running iOS14.4.2 then the phone was found when selecting Attach To Process.

    Has a bug been opened for this yet? If not, I can add one.
     
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Here is one possible work around from early investigation. In Rider (and I think Visual Studio as well), it is possible to manually enter the IP address and port to connect to the Unity player running on the device.

    This seems to work in the cases we have seen - the debugger engine is actually waiting for a connection, but the communication of that information to the IDE is the broken part.

    To do this, find the IPv4 IP address of the device (something like 192.168.0.102) in the iOS settings. Then use that IP address and the port 56000 from the IDE. With those steps, I am able to get the debugger to connect properly, even when it is not shown in the list of Unity players to debug.
     
  32. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  34. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    It looks like I've tracked down the cause of this issue.

    It seems some recent versions of iOS changed the order IP addresses are returned from the getifaddrs API. Unfortunately the code in Unity that broadcasts information to IDEs like Rider and Visual Studio was dependent on a specific order of those IP addresses.

    We've made a fix to make the code no longer depend on that order, which corrects this issue.

    Details about when this will be available in Unity releases will show up on the issue tracker link: https://issuetracker.unity3d.com/issues/managed-debugger-does-not-work-on-ios-16

    In the mean time, it is possible to work around this problem by explicitly using the IP address of the iOS device.
     
    leiferic likes this.
  35. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    Same issue here. I can connect with Unity profiler and with Rider but not with Visual Studio 2022 Mac. I have tried using the IP I can enter it in the Attach to process window as Attach to but then the OK button disables as if the Attach to field works on only as a filter/search for the list of attachable processes.
     
  36. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This does sound like a slightly different issue than some of the other discussed there. It almost feels like the GUI of Visual Studio is not behaving as expected.

    To be clear though, can you have a look a the Xcode console when the app is running? It should have output like this:

    Multi-casting "[IP] 10.0.1.152 [Port] 55000 [Flags] 3 [Guid] 2575380029 [EditorId] 4264788666 [Version] 1048832 [Id] iPhonePlayer(Example-iPhone):56000 [Debug] 1 [PackageName] iPhonePlayer" to [225.0.0.222:54997].

    (See https://docs.unity3d.com/Manual/ManagedCodeDebugging.html for more details.)

    That first IP address should be the one where the managed debugger is listening. You can attach with that IP address and port 56000. Will that work in Visual Studio?
     
  37. trond-agens

    trond-agens

    Joined:
    Sep 30, 2021
    Posts:
    6
    Due to the issue in Rider ( https://github.com/JetBrains/resharper-unity/issues/2304 ), we've also been testing Visual Studio for Mac for debugging, and also had the same problems manually connecting. Turns out that Visual Studio for Mac doesn't really care where the broadcast message comes from, so it seems like sending UDPs from the dev machine allows Visual Studio for Mac to connect and debug (this could be done from Unity on the iPhone in C# as well). Stepping and variable inspection works as one would expect.

    This workaround python script works on my setup (device is running iOS 16.3.1):
    https://gist.github.com/trond-agens/3961db548f74d1e05153a2041d92fa98 (EDIT: You must adjust the IP ranges to match your local network and device)
     

    Attached Files:

    leiferic and JoshPeterson like this.
  38. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I'm having the same problem, and can't figure out where to manually enter in the IP in VS Mac. When I go to Run > Attach Process, it only lists what it's detected. Where am I manually entering in the IP? Thanks.
     
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    From the Microsoft devs who work in VS Mac:

    We do not have the same "enter manual IP" button unfortunately. But as a workaround in Tools/Preferences/Tools for Unity, enter the ip/port like 192.168.1.1:56000 in the Saved debug targets text box, then make sure Use saved debug targets is checked. Then when clicking to Attach to Unity in the main debug bar, it will show this specific IP/port in the comboxbox so you can use it.
     
    Marks4 likes this.
  40. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    548
    JoshPeterson likes this.
  41. leiferic

    leiferic

    Joined:
    Dec 31, 2020
    Posts:
    2
    @JoshPeterson I tried this workaround but I still don't see my IP when I go to Attach to Processs. This is VS 2022 for Mac. Were you able to make it work?

    I'm really glad you found out the cause of this issue! I'm looking forward to having the fix in Unity.

    Screenshot 2023-04-11 at 16.24.03.png Screenshot 2023-04-11 at 16.24.28.png
     
  42. leiferic

    leiferic

    Joined:
    Dec 31, 2020
    Posts:
    2
    This is fantastic! Works perfectly.