Set up your HoloLens to use the Windows Device Portal


Before accessing the Windows Device Portal, you need to set it up on HoloLens:
1. Put on your HoloLens device and turn on the power.
2. Do the bloom gesture to open the Start menu.
3. Go into Settings
4. Select the Update & Security menu item.
5. Select the For developers menu item.
6. Turn on Developer Mode.
7. Scroll down and turn on Enable Device Portal.


Using the Windows Device Portal - Mixed Reality | Microsoft Docs


Connect with Wi-Fi

  1. Connect your HoloLens to Wi-Fi.
  2. Look up your device’s IP address. – To find the IP address on the device, go to Settings > Network & Internet > Wi-Fi > Advanced Options. The IP address is the set of numbers given for IPv4 Address. It will be something like
  3. From a web browser on your PC, go to https://<YOUR_HOLOLENS_IP_ADDRESS>

You will receive a warning that Your connection isn’t private


Ignore it and hit the Advanced button


You’ll receive more warnings, ignore them and hit the continue to (unsafe) link



You’ll be prompted to sign in. Use the Username (email) and password you signed into the device with, and then press the blue sign in button.



This will now load the Windows Device Portal to your Hololens.



Click on Views and Apps to load the app page.



Then click on the Choose File button to select your app to install



Navigate to where you have saved the Visual Studio Master Folder, select the YourAppNameMaster.apx file and hit open



It will start to upload to the Hololens



It will display  the message Package Successfully Registered when complete. Hit the Done button.



The App is now installed and ready to play on the Hololens 2. On  the Hololens Headset go into apps and select your app to load it.





NowSo I needed to create a Hololens 2 App and deploy it to an actual Hololens 2 that I had with me for development, AND I needed to save a copy of the compiled app that could be copied onto a Hololens 2 that my client had in another office. It was a very convoluted process so I thought I would document it now so I wouldn’t forget it for next time round.


Before you start make sure you have the following

Unity 2019.4.4f1 

MRTK 2.4.0 

Visual Studio 2019


The Best Tutorial on Set Up

I could go through and tell you how to create a Unity file that will run on the Hololens2, but really, just follow this one that Microsoft put out. It is the best.

Just go through that page and you have set up your basic Unity MRTK file that compiles to the Hololens 2 through Visual Studio.



This is where is gets fiddly and you need to set up certificates and stuff. So…. let’s get started


In Unity, open your Player Settings File > Build Settings > Player Settings.

In the Player Settings Window Expand the Publishing Settings

Scroll down to  the Certificate section and click the Create… button



A pop up box will appear and ask you to fill in a Publisher (I usually put in either my client name or my Sole trader name), and a password. Do this and then click Create



Now go back to Visual Studio and in the Solution Explorer window expand your app and locate the Package.appxmanifest file. Click on it to open it.



Click on the Packaging heading and then click on the Choose Certificate button



Click on the Select from file… button



Navigate to  the Project Assets folder (make sure it’s not the Builds Asset folder!) and select the WSATestCertificate.pfx file



Now remember in Unity we gave the certificate a password, you’ll need to enter that now and press OK


Now click on View Full Certificate



And click on Install Certificate


Choose the Current User radio button and click Next



Choose the Place all certificates in the following store radio button and click Browse



Choose the Trusted Root Certification Authorities and click OK



Click Next



Click Finish



You’ll get a Security Warning. Click Yes



Then you’ll get a message that the Import Was Successful. Hit OK



And click OK



Now right click on your app in the Solution Explorer Your App > Publish > Create App Package



Select Distribution Method. Choose the sideloading radio button and click Next



Make sure the radio button Yes use the current certificate is selected and click Next



Hololens2 needs ARM64 so make sure that checkbox is selected also and hit Create



Navigate to the folder in Windows Explorer that you gave as your file path to save the packages, and you can send these to your tester to save onto their Hololens 2.



I have another blog post that shows you how to copy it onto your Hololens 2 here



using UnityEngine;
using UnityEngine.Windows.Speech;

public class SpeechRecogniser: MonoBehaviour
protected DictationRecognizer dictationRecognizer;

void Start()


public void startDictationRequest(){

// If you are using the MRTK and have phrase recognition running, then you can't use both at once,
// so you need to turn it off with the following line
if (PhraseRecognitionSystem.Status == SpeechSystemStatus.Running)



public void stopDictationRequest(){

// If you are using the MRTK and turned off phrase recognition to enable dictation
// you need to turn it back ON again with the following line
if (PhraseRecognitionSystem.Status != SpeechSystemStatus.Running)


private void DictationRecognizer_OnDictationHypothesis(string text)

// So in here is the hypothesised text. It's quick, like as fast as it's spoken you'll get the string passed in here
// but it's slightly less accurate. So test what you get and see if it's close enough,
// otherwise do your checking for your phrases in the OnDictationResult method

if(text.Contains("your required phrase here")){
do something here

private void DictationRecognizer_OnDictationComplete(DictationCompletionCause completionCause)
switch (completionCause)
case DictationCompletionCause.TimeoutExceeded:
case DictationCompletionCause.PauseLimitExceeded:
case DictationCompletionCause.Canceled:
case DictationCompletionCause.Complete:
// Restart required
case DictationCompletionCause.UnknownError:
case DictationCompletionCause.AudioQualityFailure:
case DictationCompletionCause.MicrophoneUnavailable:
case DictationCompletionCause.NetworkFailure:
// Error

private void DictationRecognizer_OnDictationResult(string text, ConfidenceLevel confidence)

// Debug.Log("Dictation result: " + text);
messageText.text = "RESULT CONTAINS IN : " + text;
// Debug.Log("RESULT does not CONTAIN IN!!!");
private void DictationRecognizer_OnDictationError(string error, int hresult)
messageText.text = "Dictation error : " + error;
Debug.Log("Dictation error: " + error);
private void OnApplicationQuit()
private void StartDictationEngine()
dictationRecognizer = new DictationRecognizer();
dictationRecognizer.DictationHypothesis += DictationRecognizer_OnDictationHypothesis;
dictationRecognizer.DictationResult += DictationRecognizer_OnDictationResult;
dictationRecognizer.DictationComplete += DictationRecognizer_OnDictationComplete;
dictationRecognizer.DictationError += DictationRecognizer_OnDictationError;
public void CloseDictationEngine()
if (dictationRecognizer != null)
dictationRecognizer.DictationHypothesis -= DictationRecognizer_OnDictationHypothesis;
dictationRecognizer.DictationComplete -= DictationRecognizer_OnDictationComplete;
dictationRecognizer.DictationResult -= DictationRecognizer_OnDictationResult;
dictationRecognizer.DictationError -= DictationRecognizer_OnDictationError;
if (dictationRecognizer.Status == SpeechSystemStatus.Running)

Right, so classes have a number of methods in them and it can get a bit confusing as to when each of them are called, especially when you require a very specific sequence of events to occur.

So let’s say that you are instantiating a prefab from a class method.

 yourPrefab yPre = Instantiate(yourPrefab, transform.position, transform.rotation);
.SpawnAsteroid(); = "Asteroid_" + i.ToString("00");
        // Find a good location for the Asteroid to spawn
        Vector3 pos;
            pos = ScreenBounds.RANDOM_ON_SCREEN_LOC;
        } while ((pos - PlayerShip.POSITION).magnitude < MIN_ASTEROID_DIST_FROM_PLAYER_SHIP);

        ast.transform.position = pos;
        ast.size = asteroidsSO.initialSize;

Scriptable Objects have 2 major uses

  1. Saving and storing data during an editor session
  2. Saving data as an asset in our project for use at runtime

Things to Note

  1. In the editor we can save data to the SO during edit and runtime
  2. In a deployed build we can only read the data from the SO, we cannot save to it. – so no good for saving game state data.

So what’s good about Scriptable Objects

So you can make your scriptable object an Asset and create one in your Project panel with the “Create” menu. You can also define the name of your scriptable object as it appears in the create menu.

Adding your Scriptable Object to the Unity “Create” menu

 [CreateAssetMenu(menuName = "Scriptable Objects/YourObjectName", fileName = "YourObjectName.asset")]

Now once you have created your scriptable object asset, it’s public properties will be available in the inspector simply by selecting it in your project panel. You don’t need to attach it to a scene gameobject in order to be able to view and edit the data.

Why not just use a class?

Well yes you could, but using a scriptable object to store unchanging game data is probably the most efficient way. It creates just one set of data that remains constant, and everything in your file can access this one copy, rather than creating an instance of the data for every gameobject that uses it.


Serialization of Scriptable Objects

Two important attributes to know about



Classes and struct need to be [Serializable]. All public fields are then serialized. Add it above the class definition.

public class MyScriptableObject : ScriptableObject

In Unity, the [SerializeField]  attribute allows you to have private script variables that are exposed in the Inspector. This will let you set the values in the editor without giving access to the variable from other scripts.


So what does this word “static” do to variables and methods? Well a couple of things.

  1. static variables and methods that are public are accessible from anywhere without having to first reference or instantiate the class that they are in. Note though that if they are private, they can not.
  2. They make variables class variables, rather than instance variables. This comes in handy with games especially when you are creating multiple enemies or bullets or obstacles and you want to keep a total count of them. Rather than each instance of the enemy/bullet/obstacle keeping a count, the class as a whole keeps count.
using UnityEngine;
using System.Collections;

public class Obstacle
    //Static variables are shared across all instances of a class.
    public static int obstacleCount = 0;

    public Obstacle()


    static public Obstacle SpawnObstacle()
        //Increment the static variable to know how many
        //objects of this class have been created.

        GameObject oGO = Instantiate<GameObject>(GameManager.ObstacleSO.GetObstaclePrefab());
        Obstacle obst = oGO.GetComponent<Obstacle>();
        return obst;


Now one of the cool things about having a static method is that you can reference them directly and I’ll show you the code for that here.

using UnityEngine;
using System.Collections;

public class GameManager
    void Start()
        for (int i = 0; i < 3; i++)
            Obstacle obst = Obstacle.SpawnObstacle();
            Vector3 pos = ScreenBounds.RANDOM_ON_SCREEN_LOC;
            obst.transform.position = pos;

        //You can access a static variable by using the class name
        //and the dot operator.
        int x = Obstacle.obstacleCount;