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. Dismiss Notice

Resolved Replace "selectingInteractor"

Discussion in 'XR Interaction Toolkit and Input' started by Programer_YEAA, Jul 24, 2022.

  1. Programer_YEAA

    Programer_YEAA

    Joined:
    Jun 3, 2022
    Posts:
    91
    I saw a tutorial on YT and he made this funktion. What bothers me is that unity does not recomend to use "selectingInteractor". I shuld either do [System.Obsolete] or replace "selectingInteractor" with interactorsSelecting, GetOldInteractorSelecting or isSelected.

    If I do "[System.Obsolete]" it complaines about an another funktion. I also don't understand how to use interactorsSelecting, GetOldInteractorSelecting and isSelected in this case.

    I tried ro read about the options on this page but they did not realy explain that much. https://docs.unity3d.com/Packages/c...it_IXRSelectInteractable_interactorsSelecting

    What shuld I replace "selectingInteractor" with to get a similar effect?

    Code (CSharp):
    1. private bool IsControllerActionBased(out ActionBasedController controller)
    2.     {
    3.         controller = null;
    4.  
    5.         // Needs to at least by a Base Controller Interactor
    6.         if(selectingInteractor is XRBaseControllerInteractor interactor)
    7.         {
    8.             // Make sure that Controller is Action_Based
    9.             if(interactor.xrController is ActionBasedController actionController)
    10.             {
    11.                 controller = actionController;
    12.             }
    13.         }
    14.  
    15.         // Return a bool so we don't need this null-check else where
    16.         return controller != null;
    17.     }
     
  2. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    220
    If your interactable object can only be selected by one interactor at a time (which is the default case where Select Mode is set to Single), you can replace it with this code:

    Code (CSharp):
    1. private bool IsControllerActionBased(out ActionBasedController controller)
    2. {
    3.     controller = null;
    4.  
    5.     // Needs to at least by a Base Controller Interactor
    6.     if (isSelected && interactorsSelecting[0] is XRBaseControllerInteractor interactor)
    7.     {
    8.         // Make sure that Controller is Action_Based
    9.         if (interactor.xrController is ActionBasedController actionController)
    10.         {
    11.             controller = actionController;
    12.         }
    13.     }
    14.  
    15.     // Return a bool so we don't need this null-check else where
    16.     return controller != null;
    17. }
    The
    interactorsSelecting
    is a list of the interactors that are currently selecting the interactable in the order that they selected.

    The
    GetOldestInteractorSelecting
    is an extension method to get the [0] element (oldest interactor since the list is ordered from oldest to most recent), or null if not selected. Since it's an extension method, in your interactable script, you would replace
    selectingInteractor
    in your original code with
    this.GetOldestInteractorSelecting()
    if you wanted to use that method instead.
     
  3. Programer_YEAA

    Programer_YEAA

    Joined:
    Jun 3, 2022
    Posts:
    91
    Ah ok, thx :)
     
    chris-massie likes this.