Motion controller model not always loaded when playing in Editor
Overview
Motion controller model not always loaded when playing in Editor
Expected Behavior
Motion controller model loaded when playing in Editor
Actual Behavior
Sometimes the motion controller model is not loaded when playing in Editor
Steps to reproduce
Play in editor Immediately activate the window of another program
I made a little debug taking a look at the source code of MotionControllerModel.dll. The dll make a request of SpatialInteractionManager for the active window, so if you change the window when the toolkit is trying to get the model, the model is not loaded. I modified the code of the dll to trace some messages.
When the model is not loaded because the active window is not Unity I get:

When the model is loaded the active window is with class name 'UnityHoloInEditorWndClass' and I get:

Sometimes also if the focus is on Unity, the model is not loaded. In this case the active window is with class name 'UnityContainerWndClass' (the main window of Unity):

When the model is not loaded it seems that Unity doesn't have a top level window with class name 'UnityHoloInEditorWndClass':

When the model is loaded it seems that Unity always has a window with class name 'UnityHoloInEditorWndClass' but it is not a top level window:

When the model is not loaded this two workarounds can be usefull:
- Stop the app, close the portal and restart the app letting Unity to start the portal. or
- Stop the app and switch off the controllers. Start the app and then switch on the controllers.
Unity Editor Version
2017.3.0f3
Mixed Reality Toolkit Release Version
Current release
The gLTF loader is being updated with the latest version from the provider, so this test case will need re-testing then. But it sounds like a Unity importer issue with them disposing but not properly regenerating internal code when the Unity editor goes out of focus.
Ok, let me know when I can test it again Thanks Ivan
@DDReaper this is coming from the Editor loading DLL I wrote in the native Toolkit and is in the layer before the model gets to the glTF loader.
I've seen this as well, but haven't yet been able to properly debug, so this info is incredibly helpful!
@ivan2007 Do you think this is a bug in the DLL, where perhaps we're running into a race condition where we ask for the sources before that window is created? Or do you think there's a Unity bug, where they're inconsistently creating that window?
Also, @ivan2007, does changing the call to GetActiveWindow() in line 23 to FindWindow(L"UnityHoloInEditorWndClass", NULL) improve consistency?
@keveleigh, that was the first solution that I tried but it is not sufficient. It seems that a windows with class name 'UnityHoloInEditorWndClass' is necessary but not sufficient to load the models. I think that we are not running into a race condition because the models are loaded only when the sources are detected from Unity. The best solution could be if unity tell us what is the window that detected the sources. I think that ask for the current active window is not robust but I think also that there is a Unity bug. Ivan
@keveleigh, in this case the class name of the active window is 'UnityHoloInEditorWndClass' but there aren't sources for that window:
I can't understand this.
I think we need more details from Unity on how they register that class and then they create the holographic window.
Ivan
@keveleigh, I have attached the code of MotionControllerModel that I am using for the test. The strategy to find UnityHoloInEditorWndClass is this:
- Search for top level windows
- Search for all windows of Unity process
- Active window Now the correct window seems always found. I have still seen cases (rare) where no sources are found for the correct window. I think that another critical point could be the call GetDetectedSourcesAtTimestamp. We don't know what was the exact time when the source has been detected. SpatialInteractionSourceState has a property with the time stamp but the Unity class InteractionSourceState not.
@keveleigh, Looking better at the toolkit code I see that StartTrackingController is not only called when the source is detected but even before (Awake). I think that this could be a problem because in my tests I saw that if I call GetCurrentReading immediately before TryGetMotionControllerModel sometimes there aren't source available. In this moment I can't test it but I think that could explain what I have seen.
@keveleigh

Keep getting these exceptions from the controller model dll as well. Not sure if it's related.
Hello,
I am using 2017.2.0p2-MRTP5 build, and having the same issue.
This should be fixed in the 2017.4.3 release. Please reopen if not.