Search code examples
unity-game-engineaugmented-realityhololensmrtkwindows-mixed-reality

Movement of objects not persisting through world locking tools?


I am making a mixed reality game in unity 2022.3.20f1 for the HoloLens 2. I am using MRTK 3 and a fork of world locking tools updated to work with MRTK 3 as the official version is incompatible (link to that fork here). In the game somebody sets up the scene to fit the real environment before a player plays the game so I want world locking tools to remember where these objects are placed in this set up phase after which they will be made immovable for the player.

World locking tools are definitely working as object positions persist between sessions if I close the application in the background. If i don't close the application in the background it will also persist when I move an object to a different location. But the issue is that if I move the object and then fully close the application or turn off the HoloLens it will move the object back to where it was before I moved it.

I tried simply dropping in the world locking tools manager into my hierarchy which worked for world locking static objects. I also tried disabling auto save and calling the save after the user is done placing the object but that changed nothing.

My inspector of the world locking context script: here

And the test script I used to manually save the location: here

does anybody have any idea what I'm doing wrong here?


Solution

  • World Locking Tools for Unity provides a stable and reliable world-locked coordinate system, binding the virtual/holographic world to the physical world. It is not intended to save the location information of game objects. As Persisting spatial coordinate systems | Microsoft Learn mentions, only the following data will be saved. Game object is not part of it.

    • Spatial Anchors: The underlying network of spatial anchors created and maintained internally by World Locking Tools' Anchor Manager supplies the requisite binding to the real world. Those anchors are persisted via the platform's underlying storage mechanism.
    • Engine State: Engine state is persisted to allow the engine to resume its current mapping. Restoring this state removes such indeterminacies as the initial pose of the head in the previous session(s).
    • Space Pinning: If the application has applied any further Space Pins to force alignment of modeling coordinates to the real world at a discrete set of points, that mapping is also persisted.
    • Coordinate Space: World Locking Tools persists the coordinate space relative to the physical world by saving an internal graph of local spatial anchors.

    After WLT generates a stable and reliable world-locked coordinate system and binds the virtual/holographic world to the physical world, you only need to save the coordinates and state change information of the game object, and load the corresponding coordinates and states when you open the game. WLT will synchronize it with the physical world. It's like a normal game's coordinate system is bound to the game world model, and you only need to record changes in the coordinates of the item to then load the item's position.