Search Unity

Question InvalidOperationException on XRInteractionManager

Discussion in 'XR Interaction Toolkit and Input' started by Aupuma, Jan 19, 2021.

  1. Aupuma

    Aupuma

    Joined:
    Feb 15, 2017
    Posts:
    42
    Hi! My app is throwing the next error each time I grab or drop a Grab Interactable:
    InvalidOperationException: Collection was modified; enumeration operation may not execute.

    It takes to the XRInteractionManager script, line 97, on the interactors loop:
    Code (CSharp):
    1.         void Update()
    2.         {
    3.             ProcessInteractors(XRInteractionUpdateOrder.UpdatePhase.Dynamic);
    4.  
    5.             foreach (var interactor in m_Interactors)
    6.             {
    7.                 GetValidTargets(interactor, m_InteractorValidTargets);
    8.  
    9.                 ClearInteractorSelection(interactor);
    10.                 ClearInteractorHover(interactor, m_InteractorValidTargets);
    11.                 InteractorSelectValidTargets(interactor, m_InteractorValidTargets);
    12.                 InteractorHoverValidTargets(interactor, m_InteractorValidTargets);
    13.             }
    Does someone know what could be causing it?
     
  2. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    This can occur if during the event handlers (such as for Hover or Select events), you are enabling or disabling an Interactor or Interactable. Upon enabling or disabling, the Interactor/Interactable will register or unregister itself from the Interaction Manager, modifying that list as they are being enumerated. This is a known issue that will be fixed in a future version.

    As a workaround until a fix is released, you will need to call into a custom behavior during the event and have it record that it needs to enable or disable the object rather than doing it directly from the event in the Inspector. Then during Update of the script, enable or disable the other behavior that you have queued up. This will allow the Interactor or Interactable to change registration with the Interaction Manager when it is safe to do so.
     
  3. iQuentin

    iQuentin

    Joined:
    Jan 18, 2017
    Posts:
    3
    Hi Chris-massie,
    do you know if this problem has been fixed and in which version of Unity? I still have this issue today (i'm on 2021.3.11f1). Thx
     
  4. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    That issue should be fixed as of 2.0.0 of the XR Interaction Toolkit, which is available in all Unity Editor versions. Try opening Window > Package Manager and updating the package version to the latest recommended.

    If you are still seeing an error after upgrading, submit your project using Help > Report a Bug. I may also be able to help if you post the full stack trace that appears in the Console window so I can get an idea of what is going wrong.