Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question ARFoundation : ARAnchor + ARWorldMap on iOS

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

  1. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    29
    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:
    984
    In my tests, anchors are saved automatically into the ARKit World Map. And they reappear automatically after the reload.

    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?
     
  3. FOKSlab

    FOKSlab

    Joined:
    Jun 27, 2017
    Posts:
    29
    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:
    29
    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:
    516
    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:
    29
    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:
    29
    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:
    516