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

Bug XR Interaction Toolkit UpdateStayedColliders Performance Issues

Discussion in 'XR Interaction Toolkit and Input' started by VRGroupRWTH, Mar 1, 2023.

  1. VRGroupRWTH

    VRGroupRWTH

    Joined:
    Oct 23, 2021
    Posts:
    10
    Hello,

    We ran into an issue with the direct interactor in the XR Interaction Toolkit v.2.1.1: When scaling our world down/our users up while they have a (potentially deactivated) Direct Interactor on their hands, sometimes absurd lag could be observed. A little digging revealed UpdateStayedColliders was the issue, because there are potentially a lot of small colliders staying/entering/leaving the Direct Interactor's Influence per frame, even though nothing is being interacted with. The code there is quite imperformant and makes direct interactors in combination with many small colliders impossible for us.
    Would be great if someone could take a look at that.


    Could this be solved by:
    "
    • Fixed potential invalid stayed colliders list in XRDirectInteractor and XRSocketInteractor when the interactor is disabled while in contact with a collider.
    "?
     
  2. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    156
    Hey if you have a repro project you want to link here it would be appreciated.
     
  3. VRGroupRWTH

    VRGroupRWTH

    Joined:
    Oct 23, 2021
    Posts:
    10
    I'll try and set up a minimal example, but noticed the issue isn't as straightforward to repro as I was initially assuming. Will get back as soon as I have some free time, thanks for already answering :)
     
  4. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    We have a similar issue with XRSocketInteractor.UpdateCollidersAfterOnTriggerStay() causing a massive frame drop making our game unplayable.

    Using version 2.0.4.
     
  5. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    Found the line of code causing the issue in XRSocketInteractor.cs @ericprovencher

    In the coroutine UpdateCollidersAfterOnTriggerStay:

    m_TriggerContactMonitor.UpdateStayedColliders(m_StayedColliders) - for some reason m_StayedColliders has over 600k collider objects in it. It seems like the m_StayedColliders list continues to populate via OnTriggerStay when the XRSocketInteractor is disabled, but never gets cleared properly and the list size spirals out of control.

    The issue can be reproduced when disabling an XRSocketInteractor while it is in the presence of other colliders nearby.
     
    Last edited: Mar 6, 2023
  6. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    156
    Thanks for narrowing it down. 30k objects is quite a lot for that list! Might be good to introduce some maximum number of of contacts monitored at a time to prevent this issue. We can expose that limit to the editor.
     
  7. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    Hey Eric, just updated my post above. In my setup, there are only a small # of colliders contacting the socket but the list of colliders is never cleared properly and re-adds the same colliders every frame.

    Will upgrade to v2.3 and try again.
     
    Last edited: Mar 6, 2023
  8. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    156
    Hmm if that's the case it's definitely a bug. I'll look into that cheers.
     
  9. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    156
    Can you provide more info on how you're getting this to occur?
    I'm noticing that the socket interactor stops the coroutine and clears the list of stayed colliders if you disable the component, so it shouldn't keep adding to the list. Perhaps if the socket interactor stops being registered this occurs, but I'm not sure what steps you're taking to stop the registration.
     
  10. unitydreamer29

    unitydreamer29

    Joined:
    Dec 27, 2020
    Posts:
    47
    I just upgraded to v2.3 and it seems like this issue is resolved (was on 2.0.4 prior to this). When comparing the two code versions I see the stop coroutine added OnDisable in XRSocketInteractor so I believe this should resolve the issue for us.
     
  11. ericprovencher

    ericprovencher

    Unity Technologies

    Joined:
    Dec 17, 2020
    Posts:
    156
    Ok glad to hear!
     
  12. VRGroupRWTH

    VRGroupRWTH

    Joined:
    Oct 23, 2021
    Posts:
    10
    Oh good to know, we're updating to v2.3 next week as well, so I'll let you know if this resolves our issue as well. Thanks a lot for all the responses!