Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Any way to know at OnSelectExiting that interactable is being selected by another interactor?

Discussion in 'XR Interaction Toolkit and Input' started by Devil_Inside, Apr 28, 2021.

  1. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    I have a simple situation: I have a pocket, a key inside that pocket and a lock.
    If I take the key into one hand and release it mid air I want the key to fly back towards the pocket.
    If I take the key and insert it into the lock, I want the key to stay in the lock.

    How would I go about implementing this?

    My first idea was the following:
    Code (CSharp):
    1. public class Key: XRGrabInteractable
    2. {
    3.     protected override void OnSelectExiting(SelectExitEventArgs args)
    4.     {
    5.         base.OnSelectExiting(args);
    6.         GoBackToPocket();
    7.     }
    8.  
    9.     protected void GoBackToPocket()
    10.     {
    11.         // Fly back to pocket
    12.     }
    13. }
    However when I insert the key into the lock, the lock socket "grabs" the key from my hand, the key's OnSelectExiting method is executed, and the key starts flying towards the pocket. How can I know at OnSelectExiting execution time that the interactable is being selected by a different interactor right away instead of being left alone?
     
  2. eitanbariboa

    eitanbariboa

    Joined:
    Mar 19, 2020
    Posts:
    26
    Did you find a solution for that?
     
  3. DanMillerU3D

    DanMillerU3D

    Unity Technologies

    Joined:
    May 12, 2017
    Posts:
    26
    Right now there is no information in the eventargs relative to the XRGrabInteractable that will give you this information. We have it in the backlog to add context hints to select event args to describe the reason for the change which would enable this.

    Currently you could override the ResolveExistingSelect method in the XRInteractionManager to determine at a global level that it is being grabbed by the socket and not execute the GoBackToPocket or additional logic.
     
    Devil_Inside and eitanbariboa like this.
  4. eitanbariboa

    eitanbariboa

    Joined:
    Mar 19, 2020
    Posts:
    26

    I tried to implement it but with no success. It returns true even if no other interactor is trying to select it.

    How can i implement so only if another interactor is trying to select it will return true (meaning someone is trying to take from the previous interactor) and if the item is just being diselect it will return false (meaning the interactor just dropped the item).


    Code (CSharp):
    1.         protected override bool ResolveExistingSelect(IXRSelectInteractor interactor, IXRSelectInteractable interactable)
    2.         {
    3.             return base.ResolveExistingSelect(interactor, interactable);
    4.         }
    5.         public void TryingInteractorCheck(IXRSelectInteractable interactable)
    6.         {
    7.             foreach (var inter in FindObjectsOfType<XRBaseInteractor>())
    8.             {
    9.                 Debug.Log(ResolveExistingSelect(inter as IXRSelectInteractor, interactable) + inter.gameObject.name);
    10.             }
    11.         }
    12.  
    This an example of what i tried to do. to check if any other interactor is trying to select the interactable. (return false if not trying and true if trying to select)