Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

How do I add a DirectionIndicator via C# script?

I've created a Cube and Sphere GameObjects and have the HoloLensCamera and Cursor from the HoloToolKit.

If add a DirectionIndicator component to the Sphere through Unity and configure the Cursor and Direction Indicator Object in the Inspector, the DirectionIndicator works when I deploy to my HoloLens.

However if I use the following code, instead, I get an exception at run-time (the code is in the Start method of another component):

var sphere = GameObject.Find("Sphere");
var directionIndicator = sphere.AddComponent<DirectionIndicator>();
var cursor = GameObject.Find("Cursor");
directionIndicator.Cursor = cursor;
directionIndicator.DirectionIndicatorObject = GameObject.Find("Cube");

Here's the exception I get:

Exception thrown: 'System.NullReferenceException' in Assembly-CSharp.dll
NullReferenceException: Object reference not set to an instance of an object.
   at HoloToolkit.Unity.DirectionIndicator.Update()
   at HoloToolkit.Unity.DirectionIndicator.$Invoke9(Int64 instance, Int64* args)
   at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method) 
(Filename: <Unknown> Line: 0)

If I add directionIndicator.Awake(); then that seems to fix the issue. Is that okay to do? Is there something else I should be doing instead? I'm new to Unity and HoloLens.

Thanks in advance!

Tagged:
Sign In or Register to comment.