Search Unity

Persist hologram locations after game restart

Discussion in 'VR' started by 6ead2ebf, Jul 21, 2016.

  1. 6ead2ebf

    6ead2ebf

    Joined:
    Jul 20, 2016
    Posts:
    2
    I'm trying to allow users to launch my Unity program, position Holograms within the scene, and have those holograms remain in that position even after killing and re-starting the app.

    I've added a script to my GameObjects that allows users to gaze, then tap to re-position objects in the world. These objects stay in their positions if I go back to the shell, and then re-open the app, because the process never gets killed. If I use the device portal to kill the process, and re-open it, my objects all go back to their default locations. I'm trying to change this.

    DontDestroyOnLoad() doesn't work for this because it doesn't persist after the app is closed. I need to serialize my object transforms and read them back when the app starts. I've determined that the relevant events for doing this are MonoBehaviour::Start and MonoBehaviour::OnApplicationPause. The canonical way to do this in Unity seems to be using BinaryFormatter from System.Runtime.Serialization.Formatters.Binary (e.g. see this tutorial), however this namespace doesn't exist in HoloLens apps, because they target the Windows Store and use a cut-down C# runtime. The HoloLens app model documentation states that all file reading needs to happen using the Windows.Storage namespace APIs. I'm currently trying to get the SharpSerializer NuGet package working with the Windows.Storage file APIs, but am not sure if this is the right approach.

    I'm also wondering if Spatial Anchors automatically persist when the app re-starts - I haven't tested this yet though. Can anyone confirm this?

    Has anyone else solved this problem? Am I approaching it the right way?

    Thanks,
     
  2. jwittner

    jwittner

    Joined:
    Dec 2, 2015
    Posts:
    6
    Hi! Was linked here via: https://github.com/Microsoft/HoloToolkit-Unity/issues/129

    Checkout the WorldAnchorStore available in UnityEngine.VR.WSA.Persistence.

    If you haven't yet, I'd strongly recommend installing the offline Unity Documentation available here: http://unity3d.com/partners/windows/hololens, it contains lots of documentation on the HoloLens that is only available there - the online 5.4 docs don't have WorldAnchorStore for example, but the offline for the HoloLens Technical Preview does.