Swift : ARKit Save ARPlaneAnchor for next session

Viewed 2789

ARKit is quite new and I am quite new in swift... So I'm having some troubles...

I'd like to save the ARPlaneAnchor detected during a session and reload them when I relaunch my app. My phone will always be at the same place and I'd like to scan the room one time. And remembering the Anchor I found in the room everytime I launch the app.

I tried several solutions :

Solution1 : Save the ARPlaneAnchor using : NSKeyedArchiver.archiveRootObject(plane, toFile: filePath)

I got this error :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ARPlaneAnchor encodeWithCoder:]: unrecognized selector sent to instance

I think that maybe I can't save this kind of data locally

Solution2 : Store the datas of the ARPlaneAnchor then intantiate them when I launch the app. the datas are mainly float. I could creat ARAnchor easily, I could cast them as ARPlaneAnchor, but I could not modify the "center" and "extend" parameter of the ARPlaneAnchor because they only have a getter and not a setter. So I can't create the good anchors.

I am open to anysolution. I think I need to store the ARAnchor object, but for now I could not find a way to do it without a crash! So if someone can help me I would be very grateful.

1 Answers
Related