Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request ARAnchors are never removed when the ARAnchor component or GameObject with ARAnchor is destroyed

Discussion in 'AR' started by joensa, Nov 25, 2023.

  1. joensa

    joensa

    Joined:
    Jul 6, 2023
    Posts:
    15
    [Tested on iOS and XR Simulation - Unity 2022.3.13, AR Foundation 5.1.1 & 5.1.0]

    I have a simple scenario where a
    GameObject
    is instantiated in a given
    Pose
    . Thereafter an
    ARAnchor
    is added using
    GameObject.AddComponent<ARAnchor>()
    .

    This successfully invokes
    ARAnchorManager.anchorsChanged
    ,
    and
    ARAnchorsChangedEventArgs.added
    contains the added
    ARAnchor
    .

    But, whenever I remove the instantiated
    GameObject
    by either destroying it (with the ARAnchor), or first destroying the
    ARAnchor
    using
    Destroy(ARAnchor)
    and then destroying the
    GameObject
    ,
    ARAnchorManager.anchorsChanged
    is never invoked.

    I was able to use
    ARAnchorManager.subsystem.TryRemoveAnchor(ARAnchor.trackableId);
    ,
    and in this case the
    ARAnchorManager.anchorsChanged
    event is invoked and
    ARAnchorsChangedEventArgs.removed
    contains the removed
    ARAnchor
    .

    Before submitting a bug report, I'd like confirmation whether or not this behavior is expected.

    Thanks!
     
    Last edited: Nov 27, 2023
  2. joensa

    joensa

    Joined:
    Jul 6, 2023
    Posts:
    15
    Edit: I found that the ARAnchor is in fact removed, but the event isn't invoked when either the GameObject or ARAnchor component is destroyed.

    The same behaviour can be found with AREnvironmentProbes.
     
    Last edited: Nov 27, 2023
  3. Pitou22

    Pitou22

    Joined:
    Sep 23, 2015
    Posts:
    49
  4. joensa

    joensa

    Joined:
    Jul 6, 2023
    Posts:
    15
    Thanks @Pitou22 ! I thought I read all of the documentation, but missed that glaring Note!

    I agree, the anchorsChanged event would be very useful.
     
  5. joensa

    joensa

    Joined:
    Jul 6, 2023
    Posts:
    15
    @Pitou22 I just discovered that if you disable the ARAnchor component instead of destroying it, you will get the
    anchorsChanged
    event.

    This unfortunately doesn't work for AREnvironmentProbes.
     
  6. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    989
    @joensa This is an unfortunate oversight from past versions of AR Foundation.

    If you look at ARAnchorsChangedEventArgs, the Removed list requires a list of ARAnchor components. But if you destroyed the ARAnchor component already, it is null, and we can't send you a removed event because we don't have the ARAnchor anymore.

    I've brought up this issue in the past, but it's not currently slated for development. If you'd like to help get this on the road map, you can create a feature request on our newly updated road map here: https://unity.com/roadmap/unity-platform/arvr. This will also allow others to upvote the request.