Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug New Input System Bug with React Native implementation

Discussion in 'Input System' started by alejandrovaziri, Oct 17, 2023.

  1. alejandrovaziri

    alejandrovaziri

    Joined:
    Jul 8, 2019
    Posts:
    1
    Hi everyone,

    I am currently working on a React Native project that has a Unity game integrated to it, in this game there are several POI that open a panel that is done in React Native, closing this panel brings you back to the game. the main project is in React Native and it runs the Unity game.

    The bug i have been encountering is that when this POI is tapped and the React Native panel opens, when i come back to the game the input system is still registering as one finger being on the screen, there for when i place down my finger it triggers the two finger camera movement that is implemented (the camera has a drag behaviour with one finger and pinch to zoom with two fingers).

    So far i have tried disabling before going into the panel and enable inputs again once i am back into the game. I have tried to clear out all my input actions in the script and resetting them. Nothing so far has been able to clean the input system completely.

    Any idea of how i could deal with this bug?

    this is the code were i start initializing my input manager:

    Code (CSharp):
    1.     public IEnumerator SetupInputManager(CameraController cameraController)
    2.     {
    3.         Debug.Log("[UNITY] Input Manager Setup");
    4.         _cameraController = cameraController;
    5.         _inputActions = new PlayerInputActions();
    6.  
    7.         #if UNITY_WEBGL
    8.         physicsRaycaster.eventMask = physicsRaycasterWebGLEventMask;
    9.         yield return StartCoroutine(nameof(EnableWebGLInputActions));
    10.         #endif
    11.        
    12.         #if !UNITY_WEBGL
    13.         physicsRaycaster.eventMask = physicsRaycasterMobileEventMask;
    14.         yield return StartCoroutine(nameof(EnableMobileInputActions));
    15.         #endif
    16.         _intialized = true;
    17.         Debug.Log("[UNITY] Input Manager Setup Finished");
    18.     }
    and here is were i disable it and enable it again:

    Code (CSharp):
    1.     private IEnumerator EnableMobileInputActions()
    2.     {
    3.         Debug.Log("EnableMobileInputActions");
    4.         Touch = _inputActions.Mobile.PrimaryContact;
    5.         TouchPos = _inputActions.Mobile.PrimaryContactPosition;
    6.         Tap = _inputActions.Mobile.Tap;
    7.         PrimaryZoomPos = _inputActions.Mobile.PrimaryZoomPosition;
    8.         SecondaryZoomPos = _inputActions.Mobile.SecondaryContactPosition;
    9.  
    10.         _inputActions.Mobile.Tap.performed += HandleTap;
    11.         _inputActions.Mobile.PrimaryContact.started += StartPrimaryTouch;
    12.         _inputActions.Mobile.PrimaryContact.canceled += EndPrimaryTouch;
    13.         _inputActions.Mobile.SecondaryContact.started += SecondaryContactStarted;
    14.         _inputActions.Mobile.SecondaryContact.canceled += SecondaryContactStop;
    15.         _inputActions.Mobile.Enable();
    16.         Debug.Log("EnableMobileInputActions Finished");
    17.         yield return null;
    18.     }
    Code (CSharp):
    1.     private IEnumerator DisableMobileInputActions()
    2.     {
    3.         Debug.Log("DisableMobileInputActions");
    4.         _inputActions.Mobile.Disable();
    5.         Touch = null;
    6.         TouchPos = null;
    7.         Tap = null;
    8.         PrimaryZoomPos = null;
    9.         SecondaryZoomPos = null;
    10.         _inputActions.Mobile.Tap.performed -= HandleTap;
    11.         _inputActions.Mobile.PrimaryContact.started -= StartPrimaryTouch;
    12.         _inputActions.Mobile.PrimaryContact.canceled -= EndPrimaryTouch;
    13.         _inputActions.Mobile.SecondaryContact.started -= SecondaryContactStarted;
    14.         _inputActions.Mobile.SecondaryContact.canceled -= SecondaryContactStop;
    15.         Debug.Log("DisableMobileInputActions Finished");
    16.         yield return null;
    17.     }