How to reset the ARWorldMap data? (ARFoundation)

Hey! I have a problem with ARWorldMaps in ARFoundation. I want to reset all the trackables and all the data in a session loaded from a saved world map file. There is an obvious "Reset()" method of ARSession class, which should do that... but actually after the reset, all the world map data I previously loaded from a file, just restores (All trackables appears again, etc). The "Reset()" method in ARKitSessionSubsystem class seems like gives no effect too.

So, what's the right way of resetting a session loaded from a world map file?


Still need any help with this problem

  • What versions of ARFoundation & ARKit XR Plugin are you using?
  • To clarify, you want Reset() to remove all trackables, or to restore the previously loaded world map to its original state?

1. I'm using version 4.0.2.
2. Basically I want to clear all the stuff, to make a new clear session without any data, without any trackables. Reset() works if it is a regular session, but if it's a session loaded from AR World Map file, it keeps bringing back all the trackables, which I don't need anymore.

Gotcha. The reason this happens is because the world map is a configuration option, like plane detection. Resetting the session just clears the current trackables, but it doesn’t change the configuration. All the configuration parameters, including the world map are the same as they were before.

However, we are missing a way to “clear” the world map. So you can change it, but you can’t set it to be nothing.

Currently, the ARKitSessionSubsystem.ApplyWorldMap method only accepts valid world maps. We can change it to allow default-constructed world maps (ARWorldMap is a struct, so it cannot be null), in which case it would update the session’s configuration to remove the world map. To achieve what you want, you would write code like

public void ResetSession()
    var session = GetComponent<ARSession>();
    if (session.subsystem is ARKitSessionSubsystem subsystem)

Does that seem reasonable?

Thanks! I tried this, but I get "InvalidOperationException: ARWorldMap has been disposed." every time I apply the "default" WorldMap structure to the subsystem. How do I solve this?

Yes, as I said "the ARKitSessionSubsystem.ApplyWorldMap method only accepts valid world maps." My proposal is to change the existing package to allow for this in a non-breaking way. The code I suggested will not work today but is what you would be able to do in a hypothetical future point revision of the 4.0.x packages.

Thanks! So, I will wait for an update then!

This was a very valuable thread, I banged my head for a full day the other week, digging through the layers of foundation and ARKit.
It would be very nice to have this "flaw" documented somewhere, it looks to me that I'm not alone when I expect Reset to actually reset the session to a "default state" without any other applied changes. Also, do you have an issue ID for this?

You say that the world map is a configuration option, that is true for ARKit, but for the implementation in ARKitSessionSubsystem, ApplyWorldMap doesn't sound like configuration option. Anyway, I think that being able to "reset" the world map (and possibly other configuration options) is as important as applying an existing world map.

I have the same problem. Did someone succeed at resetting the world map completely ?

I am using ARFoundation 4.0.8 and ARKIT 4.0.8.

This is kind of critical @tdmowrer , do you have an issue ID for this?

My experience now is:

  • Once you've applied a world map you're toasted, unless there is a way to completely wipe Unity's ARSession/ARKitSessionSubsystem completely clean or restart from scratch creating a new session etc.
  • If your world map contains ARAnchors, there seem to be no way of getting rid of them (if you remove them from the ARAnchorManager, they reappear after a short while!). The only way I can think of (haven't tried) is to remove the anchors and immediately apply a new world map (before they reappear).

The Unity implementation of ARKitSessionSubsystem, especially handling the world map, is kind of useless at the moment.

@GoldARVR , @Grind

Actually, looks like ApplyWorldMap() works if you try to apply another worldmap after you previously applied one. It removes the old anchors and stuff.

So, the other hypothetical way to solve this could be to have a kind of empty world map file, and load it on Reset().
But, as @tdmowrer said before, you can't apply just an empty structure. The ar world map structure must contain something, or "InvalidOperationException: ARWorldMap has been disposed." exception will appear.

So, basically, we just need to create an empty (or almost empty) but valid AR World map file and use it on Reset().

I tried to save the AR World Map to file shortly after the app start, but it didn't work for me. After i tried to save any AR World map based on this "almost empty" file, it saved a file without any changes. Maybe I did something wrong, I'm not sure. So, you can try similar stuff, maybe it will work for you.

Anyway, if someone solve this, I would really like to see how you did it! Still need a solution.

I found something, but it is not an ideal solution and should only be temporary ...

If you come back to an ulterior version of ARFoundation (4.0.0 preview 1) and ARKit XR Plugin (4.0.0 preview 1), you can delete the ARSession component and re-add it to the gameObject that held it to create a new empty WorldMap.

Be careful about all the other XR plugin that are not needed for these specific versions, and about the files and folders that should be deleted in Assets/XR folder (only if you were downgrading the plugins).

I did not test other versions of the ARFoundation and ARKIT plugin. I hope this can help.

Make a save of your project if you are downgrading. I had a lot of problems because of that.

AR Foundation 4.1.0-preview.10 allows the ARKit ARWorldMap to be cleared by calling ApplyWorldMap with a default-constructed ARWorldMap.

Thanks for the feature! Much appreciate it!

Thanks a lot Tim, very useful feature!
My issue was as well to get rid of the ARAnchors after loading an ARWorldMap from file (using ARKit).
I used it with AR Foundation v4.0.12 and it worked w/o any issues.