microsoft / MixedReality-WorldLockingTools-Unity

Unity tools to provide a stable coordinate system anchored to the physical world.
https://microsoft.github.io/MixedReality-WorldLockingTools-Unity/README.html
MIT License
188 stars 45 forks source link

Alignment Persistence Broken - Save Never Gets Called #271

Closed Waffle1434 closed 2 years ago

Waffle1434 commented 2 years ago

Platform: Windows 10 Unity Editor 2019.4.35f1 Playmode HoloLens 2 (Holographic Remoting via Ethernet) WLT 1.5.8 MRTK 2.7.3

I updated to WLT 1.5.8, SpacePin persistence appears to be broken now. I can move SpacePins and they realign the world, but they are never saved nor loaded in future editor sessions. When running my own scenes or the example SpacePin.unity, the LocalLow\Company\Product\... directory isn't being written to for SpacePin alignment persistence anymore.

I attempted to debug: Apparently AnchorManager is some sort of null implementation, even though I am using the HoloLens 2 in editor via Holographic Remoting & tether. This results in save never being called as it believes persistence isn't supported.

private void AutoSaveTriggerHook()// WorldLockingManager.cs line 1010
{
    if (AnchorManager.SupportsPersistence)// This ALWAYS returns false as AnchorManager == Microsoft.MixedReality.WorldLocking.Core.AnchorManagerNull
    {
        /// Persistence currently only supported on HoloLens
        if (AutoSave && Time.unscaledTime >= lastSavingTime + AutoSaveInterval)
        {
            WrapErrors(saveAsync());
        }
    }
}
Waffle1434 commented 2 years ago

This seems to be the cause of what I'm experiencing:

#if UNITY_EDITOR
if (anchorSettings.NullSubsystemInEditor)// WorldLockingManager.cs SelectAnchorManager line 521
{
    DebugLogSetup($"Switching from {anchorSettings.anchorSubsystem} to AnchorSubsystem.Null because running in editor.");
    anchorSettings.anchorSubsystem = AnchorSettings.AnchorSubsystem.Null;
}
#endif // UNITY_EDITOR

Changing #if UNITY_EDITOR to #if false fixed my issue and now its persisting perfectly.

It would seem its not checking if a HoloLens is tethered in editor, and assumes none is present. I toggle certain aspects of my project if a HoloLens is detected, this is how I've reliably detected it in Editor and Standalone: Microsoft.MixedReality.Toolkit.Utilities.DeviceUtility.IsPresent SelectAnchorManager might want to check this as well in editor.

fast-slow-still commented 2 years ago

Thanks, that's a great suggestion! Also, you can disable that behavior by unchecking the "Null Subsystem in Editor" checkbox in the Anchor Management settings.

image