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 How to reset the ARWorldMap data? (ARFoundation)

Discussion in 'AR' started by Red_SIM, Sep 13, 2020.

  1. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
    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?

    Thanks!
     
  2. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
    Still need any help with this problem
     
  3. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    1. What versions of ARFoundation & ARKit XR Plugin are you using?
    2. To clarify, you want
      Reset()
      to remove all trackables, or to restore the previously loaded world map to its original state?
     
  4. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
    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.
     
  5. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    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

    Code (CSharp):
    1. public void ResetSession()
    2. {
    3.     var session = GetComponent<ARSession>();
    4. #if UNITY_IOS
    5.     if (session.subsystem is ARKitSessionSubsystem subsystem)
    6.     {
    7.         subsystem.ApplyWorldMap(default);
    8.     }
    9. #endif
    10.     session.Reset();
    11. }
    Does that seem reasonable?
     
  6. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
    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?
     
  7. tdmowrer

    tdmowrer

    Unity Technologies

    Joined:
    Apr 21, 2017
    Posts:
    605
    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.
     
  8. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
    Thanks! So, I will wait for an update then!
     
  9. Grind

    Grind

    Joined:
    Oct 22, 2008
    Posts:
    21
    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.
     
  10. GoldARVR

    GoldARVR

    Joined:
    Oct 28, 2019
    Posts:
    6
    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.
     
  11. Grind

    Grind

    Joined:
    Oct 22, 2008
    Posts:
    21
    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.
     
  12. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
    @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.
     
  13. GoldARVR

    GoldARVR

    Joined:
    Oct 28, 2019
    Posts:
    6
    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.
     
  14. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    324
  15. Red_SIM

    Red_SIM

    Joined:
    Jun 28, 2017
    Posts:
    7
  16. MaximilianFroeschl

    MaximilianFroeschl

    Joined:
    May 7, 2020
    Posts:
    2
    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.