Problem at saving and loading an AR world with anchors

Hello

I’m trying to develop an AR app where you can put an object in the world, save it, and then load it so it returns to the same place. For that, I’m using both, RealityKit and ARKit. While using RealityKit to create those objects and anchor them to the world, I use ARKit to save the world and then load it.

The problem I have is that every time it loads the world, the anchor from RealityKit becomes crazy and moves randomly to a place that it’s not supposed to be. I already know that using only ARKit it works, but I must use RealityKit for the anchors. I tried to change the transform from those anchors as well, but they don’t move at all.

I tried to reanchor them to one of the ARKit anchors that are saved, but they disappear. So, at this point I’m even wondering if it is even possible to make it work together. Thank you for your help.

Answered by Vision Pro Engineer in 745919022

You need to use ARAnchors in order to include your object's locations as part of an ARWorldMap. But you can create a link between an ARAnchor and an AnchorEntity in RealityKit. You can initialize your anchor entity with an existing ARAnchor using the init(anchor:) initializer: https://developer.apple.com/documentation/realitykit/anchorentity/init(anchor:). That way your RealityKit entities should reappear at the correct location when ARKit relocalizes and restores the anchor's positions.

Accepted Answer

You need to use ARAnchors in order to include your object's locations as part of an ARWorldMap. But you can create a link between an ARAnchor and an AnchorEntity in RealityKit. You can initialize your anchor entity with an existing ARAnchor using the init(anchor:) initializer: https://developer.apple.com/documentation/realitykit/anchorentity/init(anchor:). That way your RealityKit entities should reappear at the correct location when ARKit relocalizes and restores the anchor's positions.

Problem at saving and loading an AR world with anchors
 
 
Q