Skip to content

Lessons Learned

Erik Vullings edited this page Dec 8, 2016 · 4 revisions

Developing for Unity is quite easy at start, but I ran into several issues while developing for Hololens. Some of them I will document here.

Using external DLLs

(Source) I ran into this issue when using MQTT in the Hololens, and I ended up creating two versions of the DLL.

Unity targets Mono, which requires the plugin to be a .NET platform DLL. However, Hololens supports Windows Universal applications, which requires the plugin to be a Universal Window platform (UWP) DLL. Therefore, it is impossible to use the same plugin for both Unity and Hololens. If it works for Unity, building for Hololens will fail.

The solution is to use two versions of the plugin; a .NET platform DLL and a UWP DLL. Both DLLs should have identical interfaces in order to allow for referencing classes, methods, etc from any of the two DLLs using the same code. In case the interface is not identical, you probably have to use pragmas to distinguish between them, e.g.

#if NETFX_CORE
// Add the HoloLens DLL code
#else
// Add the Unity Editor DLL code
#endif

Assuming that you have created the two DLL files (x.dll) and (x.uwp.dll) with identical interfaces (i.e. namespace, public class names, etc), the solution should be as easy as the following:

  • Create a Plugins folder under the Assets folder in your Unity project. This is not required, but the Plugins folder is a special folder in Unity, and guaranteed to be loaded with priority.
  • Drag and drop the (x.dll) file into the Plugins folder and select it.
  • From the Inspector window under Select platforms for plugin, make sure that only Editor' is checked.
  • Create a subfolder named WSA under the Plugins folder.
  • Drag and drop the (x.uwp.dll) file into the WSA folder and select it.
  • From the Inspector window under Select platforms for plugin, make sure that only WSAPlayer is checked.
  • Now, Unity will use x.dll when you run the project on your machine and use x.uwp.dll when you build your project for Hololens.

Using .NET 4

Related to the previous issue, when adding your own code, it may be tempting to use .NET4 or higher features. Unfortunately, they suffer from the same issue as documented above. So for example extension methods cannot be used.

Using unsafe code

In the HoloToolkit, e.g. the Sharing section, they use the unsafe keyword for certain methods. This will require you to add a special file inside that folder, called smcs.rcp, which just contains one line of text, -unsafe. This will compile your code using the unsafe option. See also here.

Deploy to HoloLens error: MicStreamSelector.dll

After adding the HoloToolkit-Unity project as custom asset, we started having this error. The most annoying aspect was that I couldn't build a deployment project anymore. I had to manually add the dll from the HoloToolkit project to the appropriate folder. Although after doing that, the deploy would work, but in the output log, there was still an error message, complaining that the dll was not x86 compatible (even though it was). In the end, I removed that part from the (partially) imported HoloToolkit, and the error went away.

IMPORTANT: After going through the HoloToolkit in more detail, I noticed the following statement, which may resolve the issue (I didn't add the required Music Library capabilities): "Please make sure to add the Microphone and Music Library capabilities in your app, in Unity under
Edit -> Project Settings -> Player -> Settings for Windows Store -> Publishing Settings -> Capabilities
or in your Visual Studio Package.appxmanifest capabilities."

## Deploying to the emulator issue

When deploying to the emulator does not work (emulator freezes with the 'OS loading...' message in view), you may try this fix which works for me. It also applies when you don't have an Internet connection: since the tiles are retrieved over Internet, so we need a live network connection. No matter what I did, the emulator's Internet connection always shows disconnected, even though sometimes, I could browse on the Internet (in Edge). If you do not have an Internet connection, the following may help:

  • Close the hololens emulator
  • Open the Hyper-V manager (WINDOWS+S en type Hyper-V)
  • Go to Virtual Switch Manager in the right menu
  • Select and remove the Windows Phone Emulator Internal and the 'Microsoft Emulator NAT Switch`
  • Deploy your project again: the emulator will ask you to start in elevated mode. Select yes, and it will restore the previously deleted switches for you.
  • Wait
  • Wait some more, and the emulator will show the main menu again
  • Open the Virtual Switch Manager again, and create a bridge between the 'Microsoft Emulator NAT Switch` and your local network (you can check by right clicking on the Hololens emulator, open Settings, whether you are using this switch). The application should continue deploying your application. Otherwise, you can try to deploy it again.

http://localhost:xxx/ in emulator no longer retrieves data from guest PC

Previously, any reference to localhost in the emulator worked just fine and it retrieved the data from the guest machine. In the latest Unity release (5.5.0fb2 RC2), this behaviour has been 'fixed', so you cannot use it in the emulator anymore. Maybe better, since it wouldn't have worked in the Hololens anyways.