0

I have developed an application for hololens with Unity that uses the Hololens' depth camera. I built it with il2cpp scripting backend and it runs well on the Hololens when I launch it from Visual Studio 2017 (community). But I want to be able to debug the app (and have the output in visual studio console) while it is running on the Hololens (because I need the camera frame to be received to see how it works).

Moreover, I want to be able to set breakpoints in my .cs scripts files in my #UWP script parts.

I have been searching for a long time on Microsoft documentation and didn't find the specific answers I was looking for.

Nath7098
  • 41
  • 1
  • 5
  • I could be way off on this but, couldn't you just attach the debugger to the HoloLens process and set your breakpoints? – Josh Poitras Jan 30 '20 at 16:48

3 Answers3

5

The Unity - Manual and also Microsoft - Managed Debugging with Unity IL2CPP is your friend! Check the section Debugging in the Player

In short:

  • In the player settings enable the capabilities PrivateNetworkClientServer, InternetClientServer
  • In the build settings enable Development Build, ScriptDebugging and Wait For Managed Debugger.
  • Build your project to a solution. Open the solution in VisualStudio.
  • With the HL connected run it on Device. (As debug from VisualStudio or by deploying and starting it on the device itself). Alternatively via WiFi enter the IP of the HoloLens .. just takes a bit longer to deploy of course
  • Wait for the pop-up.
  • Open any script by double click from Unity in a second VisualStudio instance (so the project's c# solution is loaded)
  • Here you also set the breakpoints
  • Go to Debug-> Attach Unity Debugger
  • select the HoloLens and attach the debugger
  • on the HL close the pop-up

You can now set breakpoints and debug c# code as usual while the HoloLens is actually running the Il2CPP solution.

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • There's one missing step: you need to enable "Internet Server" and "Private Networks" capablities in the application manifest. – Sunius Feb 02 '20 at 05:10
  • Actually one more essential step; the Hololens device must not be connected via USB at the time you attempt to attach the Unity debugger, or else it won't appear in the list of debug targets. I guess only debugging over wifi is supported. Reference: https://learn.microsoft.com/en-us/windows/mixed-reality/develop/unity/managed-debugging-with-unity-il2cpp – bleater Mar 23 '21 at 22:07
  • @bleater nope .. I always debug via USB, works just fine .. the link is the same as I referenced in the answer btw ;) – derHugo Mar 24 '21 at 07:36
  • @derHugo And does debugging with breakpoints also work with code that is wrapped by macros like #if UWP or #if WINMD? – Perazim Feb 14 '22 at 10:11
  • @derHugo the solutiono provided by microsoft and you did not work for me. I made the same steps and put breakpoints into normal code like Start() and they where not triggered. – Perazim Feb 14 '22 at 11:34
1

I found the answer to my problem!

In order to debug c# code directly running on the Hololens, I did as follow:

  • In Unity :
    • Build Setting -> Player settings -> Other settings -> Scripting backend = .NET
    • Build Settings :
      • Build configuration Debug
      • check Copy reference
      • check Unity c# project
      • check development build
    • Then you can build
  • In Visual Studio 2017
    • Debug - x86 - Device (or remote machine)
    • If needed : In Solution Explorer -> For each solution -> alt+Enter -> Under Build tab check Allow unsafe code

Then you can set your break points where ever you want !

Hope this helps

Nath7098
  • 41
  • 1
  • 5
1

Just adding a note in here, if anyone should drop by: The accepted answer is not seen as a solution going forward from 2019 as .NET backend is deprecated: See ths approach for debugging:

https://learn.microsoft.com/en-us/archive/blogs/appconsult/how-to-debug-unity-projects-with-il2cpp-backends-on-the-hololens

Martin
  • 3,096
  • 1
  • 26
  • 46
Duftstenen
  • 23
  • 3