Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using persistent WorldAnchors on GameObjects spawned in runtime?

Discussion in 'AR' started by Aupuma, Sep 21, 2020.

  1. Aupuma

    Aupuma

    Joined:
    Feb 15, 2017
    Posts:
    42
    Hello, I'm building an application for Hololens 2 with MRTK where the user can select a gameobject to then place a copy of it in space. The objects need to stay in place between sessions and after rebooting the device, so I started using WorldAnchors for that purpose.

    If the objects are unique and are already placed in the scene, the Transform properties are retrieved correctly when the session is restarted. However, as gameobjects are copied and Instantiated in runtime, I save the type of gameobject and anchor name on a binary file, to then later retrieve it. This time, the correct gameobjects are instantiated but they aren't correctly placed, even though they seem to be anchored, as the app does not let you move them. Anyone has managed to achieve this?
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    What version of Unity are you using? Are you using Legacy XR or the new XR SDK plug in system?
     
  3. Aupuma

    Aupuma

    Joined:
    Feb 15, 2017
    Posts:
    42
    Thanks, but I finally solved it! The problem was the serialization of the Anchor's name. When I deserialized it, it didn't return the exact same string, so it wasn't saving the anchor correctly
     
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Awesome, glad you figured it out!
     
  5. unity_42KRDl0IMBlHfA

    unity_42KRDl0IMBlHfA

    Joined:
    Aug 4, 2020
    Posts:
    3
    I tried using ReSight SDK, worked quite well