GeoAnchor saving multiple anchors after removeall anchors method

I'm using GeoTrackingExample project from Apple and there is a bug in the logic where after you reset the AR Session, it still retains the anchor information in the URL. So the steps are as follows:

  1. start app
  2. tap in the arview and place an object
  3. select Reset AR Session from the menu
  4. tap in the arview to place an object
  5. select save anchor from the menu
  6. save file to device
  7. Reset AR Session
  8. Load the saved file

When the file loads, it will load both the initial object placed in the AR view in step 2 then removed in step 3 but when saving the added object that was placed in step 4 and reloaded, it loads both of the anchors. It should only have saved the object added in step 4, not both objects from step 2 and 4. When stepping though the code to debug, it appears that the the anchors are removed from the ARview but somehow the URL will contain the path for both the objects. What else do I need to do to clear so that objects from previous sessions are not added to the URL in the session? Is the URL modified when the object is added to an ARView? Please help! Thanks

I found the logic problem, when a session is reset, arView.scene.anchors.removeAll() statement is executed but does not clear a global variable : var currentAnchors: [ARAnchor] { return arView.session.currentFrame?.anchors ?? [] }. I'm not 100% positive but it looks like this statement adds an element in the array every time an anchor is added to a scene but does not get cleared when the anchors in the scene are removed. Anyone recommend the best way to clear the array when its a computed variable? It wont allow me to use removeall()

The example code from Apple uses a computed var to store the array of placed Geoanchors in the scene but since the computed variable is read-only, the values in the array cannot be removed when the scene is reset so it was keeping a long list every time a model was added to the scene with no way to delete them (that I know of.) Fixed the issue by not using a computed variable and modifying the code accordingly:

  • var currentAnchors: [ARAnchor] = [] // from

var currentAnchors: [ARAnchor] { return arView.session.currentFrame?.anchors ?? []}

  • append the geo anchor to the array when the anchor is placed in the scene

  • add currentAnchors.removeAll() in the reset AR session function

Not sure if this is helpful at all to anyone out there but I'm glad I figured it out! ** Anyone know why they used computed variable for storing AR Anchors?

GeoAnchor saving multiple anchors after removeall anchors method
 
 
Q