Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Attach debugger to iOS device

Discussion in 'iOS and tvOS' started by K1kk0z90_Unity, Sep 9, 2018.

  1. K1kk0z90_Unity

    K1kk0z90_Unity

    Joined:
    Jun 2, 2013
    Posts:
    90
    Hello,
    Is it possible, on Windows, to attach the Unity debugger to an iOS device running a development build?

    I have installed on my iPad (iOS 11) a development build, built using Cloud Build. While the app is running, on Visual Studio i click on Debug->Attach to Unity Debugger.... In the "Select Unity instance" window I can only see the Unity Editor, and not the iOS player on my iPad.

    If in Unity, in the Console window I try to select, instead of "Editor", "iPad Pro 10.5" Wi-Fi" (my device), I get to console the same Warning for 5 times, plus an error:
    How can I debug C# scripts running on iOS?
    Please, help me. Thank you in advance for your help.
     
  2. Ignas83

    Ignas83

    Unity Technologies

    Joined:
    Mar 26, 2013
    Posts:
    28
    That should work just make sure:
    • Script debugging is enabled.
    • .NET 4.x scripting runtime is selected (I assume this is IL2CPP project).
    • Device is on the same network as PC. Also it's best to use simplest network configuration possible. If nothing else works connect your device and PC to a separate dedicated router.
    • Let Visual Studio know where debugging symbols file (.pdb) is.
     
    zwcloud likes this.
  3. The-Real-Zap

    The-Real-Zap

    Joined:
    Jan 23, 2015
    Posts:
    7
    Hi Ignas83,

    I tried your suggestion but it didn't work out. I make a development build with script debugging enabled and runtime set to .NET 4.x, I can see my iPhone when I press 'Attach Unity Debugger' in Visual Studio, but when I click Ok it just waits a few seconds (with the circling icon, as if it is doing something) and then just nothing happens and Visual Studio remains in its initial state. I tried both Release & Debug builds, the result was the same. I suspect the problem may be the .pdb's, I couldn't see any being created, besides the 'Assembly-CSharp.pdb' in the iOS build directory under Data/Managed, which is around 50kb in size. I tried a build of one of the ARKit samples, just to be sure it has nothing to do with my code (I again set runtime to .NET 4.x and the other things), I tried to add the directory with the .pdb file under Visual Studio's Menu -> Debugger -> Options -> Symbols, I tried adding the .pdb file itself in the same place, but all of this to no avail. Do you have any idea what could be wrong? Also, do could you point to any example project/scene where above mentioned steps would indeed result the VS debugger being attached to the iOS build?

    Thanks in advance!
     
    Last edited: Feb 28, 2019
  4. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    513
    Have you tried enabling "Autoconnect profiler"? For me, if I did not enable that setting, I get the same behavior that "Failed to connect to player".
     
  5. The-Real-Zap

    The-Real-Zap

    Joined:
    Jan 23, 2015
    Posts:
    7
    Hi Neonlyte,

    I tried with "Autoconnect profiler", still the same. I can successfully attach to an Android build, if that matters. I can also connect the Console output in the Unity Editor and see the Debug.Log messages from my running iOS build, but for this checking only the "Development Build" is enough. But I still can't attach the debugger, although I see it in the possible instances I can connect to, and although I don't get any errors, it just "tries" for a few seconds and the nnothing happens :( Really weird and annoying...
     
  6. AlterVorrin

    AlterVorrin

    Joined:
    Oct 11, 2017
    Posts:
    4
    Hello!
    I'm having a similar issue, I can connect to the iOS build, from VS running on windows, I see it fine in the 'Attach Unity Debugger' window, but my breakpoints don't hit anything. I've done all the steps @Ignas83 suggested, except for letting VS know where the pdb files are. Given the ios build mostly happens on a mac, as it must, which pdb exactly shall I point VS to?

    Unity's documentation doesn't seem to discuss that side of things much, or at all for this specific issue (their mention of .pdb files seems to be specific to plugins).
    If anyone has any idea, please let me know!
     
  7. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    393
    Hi @AlterVorrin @The-Real-Zap @K1kk0z90_Unity

    For anyone who sees this post, the solution is pretty simple, you just have to enable 'Symlink Unity Libraries' along with 'Development Build' and 'Script Debugging' when building for iOS and you would be able to attach visual studio debugger.
    It is not documented anywhere so I am not sure if this is a bug in certain edge cases or the intended behaviour.
    Please check my blog post.
     
    lifestreamXR likes this.
  8. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    After enabling all three and building in Unity and then Xcode automatically, I assumed that I would see an option in Visual Studio to attach the debugger to either XCode or the iOS device itself. I still only see an option to Debug > Attach to Unity.

    EDIT:

    I ended up following the process for iOS here via Run > Attach To Process, which apparently uses TCP. My iPhone's Unity Player ended up coming up as an option after building in Xcode, though there was a decent delay. Unfortunately before it actually hits breakpoints, the app freezes up, which isn't super useful. I'm trying to debug something that only occurs on an older phone, which is perhaps why the debugging performance is also crappy.
     
    Last edited: Jul 17, 2020
  9. The-Real-Zap

    The-Real-Zap

    Joined:
    Jan 23, 2015
    Posts:
    7
    Hi again, guys! After some time, I gave it another try on another project, and I had the same problem at first. Then I disabled cellular and Bluetooth on my iPhone and suddenly it started attaching and debugging successfully!
     
  10. drew55

    drew55

    Joined:
    Dec 13, 2017
    Posts:
    44
    Anyone have any success debugging with VS Code?

    VS Code on macOS consistently can connect but 4-5 secs later I get `UnityDebug: Disconnected` (See screenshot)

    Would love to hear any tips or info, thank you. Using Unity 2020.1.13, High Sierra, Xcode 9.
     

    Attached Files:

  11. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    I didn't even know this was possible. I'm using MAC and Jetbrains Rider... I will give it a try soon
     
    MGLWall likes this.