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.

XRInput force OnSelectExit event

Discussion in 'Input System' started by whuse, Aug 6, 2020.

  1. whuse


    Aug 23, 2017
    I'm working on a mechanic similar to a slingshot. The player grabs a ball with grip button(OnSelect). While grabbed, if the user holds down the trigger button (OnActivate) it draws a line between the ball and where it was pulled from. On release of the trigger, a force is added to the ball launching it forwards. My problem is that the ball is still held while the trigger is released so the force is irrelevant. I've tried digging around to see if there is a way to force OnSelectExit but it's protected. Does anybody have any advice?

    Code (CSharp):
    1.         /// <summary>This method is called by the interaction manager
    2.         /// when the interactor ends selection of an interactable.</summary>
    3.         /// <param name="interactable">Interactable that is no longer selected.</param>
    4.         protected internal virtual void OnSelectExit(XRBaseInteractable interactable)
    5.         {
    6.             Debug.Assert(m_SelectTarget == interactable);
    7.             if (m_SelectTarget == interactable)
    8.                 m_SelectTarget = null;
    10.             m_OnSelectExit?.Invoke(interactable);
    11.         }