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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to reset meshes generated by ARMeshManager

Discussion in 'AR' started by chankeiro, Jun 22, 2023.

  1. chankeiro

    chankeiro

    Joined:
    Oct 25, 2021
    Posts:
    11
    Hello. I would like to know how to delete the meshes generated by the ARMeshManager so that I can start from scratch with new ones. I have tried the following:

    Code (CSharp):
    1. _arMeshManager.DestroyAllMeshes();
    2. _arfSession.Reset();
    DestroyAllMeshes() deletes the existing meshes, but they show up again if the ARMeshManager is still enabled. Even if I reset the ARSession inmediately after destroying the meshes, new Trackables are automatically created with the same old meshes.

    I have also tried deleting the ARMeshManager and creating a new one, but the old meshes still show up, I guess because they are not stored in the manager but in the meshing subsystem. So I tried destroying the subsystem, but after that I don't know how to restart it again. ARMeshManager.subsystem.Start() doesn't work for that.

    The only thing that allows me to completely reset the meshing subsystem is to reload the scene, but this solution does not fit into the workflow of my application.
     
    dinkDoink likes this.
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    818
    I don't fully understand your question. When you say "start from scratch with new ones", what about that is not satisfied by "they show up again if the ARMeshManager is still enabled"?

    Do you want meshes with new trackableId's specifically, or something else?
     
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    818
    Destroying the subsystem is a lot of work and may not solve your problem, but the way to do this would be:

    * Destroy the ARMeshManager
    * Destroy the ARKitMeshSubsystem
    * Create a new ARKitMeshSubsystem instance (see ARKitLoader.cs)
    * Register the new ARKitMeshSubsystem with Unity's SubsystemManager (see ARKitLoader.cs)
    * Create a new ARMeshManager
     
  4. chankeiro

    chankeiro

    Joined:
    Oct 25, 2021
    Posts:
    11
    Hi andyb. I mean exactly the same meshes, with the same size and shape, show up immediately after DestroyAllMeshes, but I want to "reset" the meshes and start scanning the space again from 0. I'll try your suggestion. Thanks a lot!
     
  5. danilo_unity17

    danilo_unity17

    Joined:
    Jan 16, 2023
    Posts:
    4
    I have the same issue. Even after calling "destroy all meshes", it seems that the meshes re-appear instantly, with the very same details as previous.

    I undestand this might get confused with simply deleting and re-scanning very fast, but I noticed that the new mesh comes in place with the very same position and details as the previous one, like there is some points cache that is not properly deleted and then it somehow notices that we are scanning the same area and fills it with the previous cache instead of scanning again.

    Like, if you scan a table from all sides, and then call destroy all meshes, when scanning again. all the details from the same table will come in place, even though we are now scanning just one side of the table
     
  6. danilo_unity17

    danilo_unity17

    Joined:
    Jan 16, 2023
    Posts:
    4
    CHANKEIRO my good man, did it work? do not wanna do all this to notice its impossible
     
  7. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    818
    @danilo_unity17 I'm not familiar with
    ARMeshManager.DestroyAllMeshes
    , but I agree that your description matches what I would expect. If you could file a bug and share your bug number in this thread that would be a huge help to start the process of assigning someone to look at this: https://unity3d.com/unity/qa/bug-reporting
     
    KyryloKuzyk likes this.
  8. chankeiro

    chankeiro

    Joined:
    Oct 25, 2021
    Posts:
    11
    After updating to ArCore Unity Extensions 1.38, I gave it another try and now the simplest code restarts the meshes:

    _arMeshManager.enabled = false;
    _arMeshManager.DestroyAllMeshes();
    _arMeshManager.enabled = true;

    But there is a caveat: I'm only working with Android, and since meshing is not supported in AR Foundation for Android devices (my understanding is that Android doesn't provide the feature yet), I'm using the Lightship library to do it. This library works alongside ARFoundation, so you just have to enable meshing through it instead of native ARFoundation. Then you can work normally with the usual ARFoundation managers. But again, this is Android. If you are working with iOS + ARFoundation meshing feature, I cannot say if this solution will work.

    This is a tutorial on how to mesh with LightShip: https://lightship.dev/docs/beta/ardk/how-to/meshing_physics_real_world/