Search Unity

Question ARFoundation : ARAnchor + ARWorldMap on iOS

Discussion in 'AR' started by FOKSlab, Dec 13, 2022.

  1. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    30
    Hi,

    I'm trying to save some objects' Poses in an AR session so I can reload them in a later session (app is closed between both session). I save and reloaded AR World Map (ARKit, my app is iOS only) but when reloading the world map no anchor can be found in ARAnchorManager (I am sure there is an anchor when saving).

    How could I do to place my objects as they were in previous session ?

    I hope you can help
    Regards,
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,145
    In my tests, anchors are saved automatically into the ARKit World Map. And they reappear automatically after the re-localization.

    There is nothing special in my setup, I simply have an ARAnchorManager.anchorPrefab populated from the inspector, and it works.

    Does ARAnchorManager.AddAnchor() return a valid anchor in your testing?
     
    Last edited: Oct 13, 2023
    viknesh2020 likes this.
  3. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    30
    Anchors are added using AddComponent<ARAnchor> on an object (AddAnchor is obsolete as per Unity documentation).

    I delete the object (and therefore ARAnchor), ARWorldMap is saved.
    I quit ,
    reload the ARWorldMap
    and get the ARAnchorManager.trackables (directly after reloading ... maybe I need to wait a bit?) and no ARAnchor can be found in the Collection.

    Any idea ?
     
  4. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    30
    I tried to wait for the AR World map status to be mapped or extending and it seems my ARAnchor is there ! I will confirm that quickly

    [EDIT] Not so easy :( ... AR world map status goes to "extending" and then no ARAnchor in the ARAnchormanager next ... :'(
     
    Last edited: Dec 13, 2022
  5. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    This sounds like you are deleting the anchor? The world map will not show deleted anchors.
     
    KyryloKuzyk likes this.
  6. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    30
    Thanks for your answer.
    I checked my code but obviously :) when world map is saved the object & anchor are still present in the scene.

    When I delete the object/anchor next I have the issue reloading AR World Map : no anchors are in ARAnchorManager.trackables at the end of ARWorldMap loading process. Same if I quit & restart the app.
    I use the sample from ARFoudnation examples to save/load the ARWorldMap and it seems OK regarding the messages I get .
    It seems after ApplyWorldMap no anchor is loaded. Anchors are saved even if no other manager is enabled in the scene (plane/trackedImage/pointClouds ...) ?

    I load the map then call

    Code (CSharp):
    1.  myARKitsessionSubsystem.ApplyWorldMap(worldMap);
    and I check the anchors in my anchor manager this way :

    Code (CSharp):
    1.         Debug.Log("Available anchors");
    2.         foreach (ARAnchor a in myAnchorManager.trackables)
    3.             Debug.Log("Anchor = " + a.name + " / " + a.trackableId.subId1 + "." + a.trackableId.subId2);
     
  7. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    30
    Ho I forgot to say : I work on Unity 2020.3.28f1 with ARFoundation/ARKit 4.2.6.
     
  8. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
  9. viknesh2020

    viknesh2020

    Joined:
    Jul 19, 2016
    Posts:
    52
    Is this possible for a Gameobject, which has <ARAnchor> component attached to it?. I tried instantiating a prefab with ARAnchor component attached to it. First I spawned them and then saved the worldmap. However, when I load the worldmap, I am unable to see the Gameobjects that I spawned. Is the Anchor component supposed to save the Gameobject as well into the worldmap?
     
  10. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,145
    ARWorldMap saves only the anchor's ID but doesn't save the GameObject attached to it. After the re-localization, you should spawn the desired GameObject yourself based on the anchor's ID.
     
  11. viknesh2020

    viknesh2020

    Joined:
    Jul 19, 2016
    Posts:
    52
    Thanks for your immediate response. Is there any API reference to find saved Anchor ID on a worldmap?
     
  12. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,145
    @viknesh2020 There is no specific API to get anchors from the worldmap, but you can subscribe to the ARAnchorManager.anchorsChanged event and listen for the anchor added event while performing the re-localization.
     
    viknesh2020 likes this.