react-native-unity icon indicating copy to clipboard operation
react-native-unity copied to clipboard

Android touch input not received/processed by Unity InputSystem

Open PierreGerbaud opened this issue 7 months ago • 2 comments

Hello! First of all, thanks for the work on this library.

I'm trying to get a Unity view with overlaid React Native components on Android. I'm using unity 6 (6000.0.42f1); Input System UI Input Module. Taps are properly registered by Android Logcat but don't reach Unity.

I manage to either:

  • Get a responsive full screen view in Unity, but no overlaid React items
  • Get overlaid React items and Unity player in the middle, but no input

What I tried:

  • added no-pointers to the React overlaid components
  • tinkering with the zIndex
  • confirmed all required scripts are working (the game is properly initializing with properties passed from React, and it sends messages to react)

My main hypothesis is on the ReactNative side, either:

  • some kind of zIndex conflict
  • an input focus issue I wouldn't think it's directly Unity related, as I manage to get the input when I drop the overlays, and the editor mode works - but i can be wrong of course.

Thanks a lot for your help!!

Image

Some possibly relevant code extracts (simplified):

AppNavigator.tsx:

{isUnityVisible && ( )} ...... const styles = StyleSheet.create({ container: { flex: 1, position: 'relative', }, unityContainer: { ...StyleSheet.absoluteFillObject, zIndex: 5, }, unityView: { flex: 1, }, navigationContainer: { ...StyleSheet.absoluteFillObject, zIndex: 10, backgroundColor: 'transparent', } });

InputManager.cs

using UnityEngine.InputSystem; InputAction pointerAction;

void Awake() { InputSystem.AddDevice<Touchscreen>(); pointerAction = new InputAction("PointerInteraction", binding: "<Pointer>/press", interactions: "Tap,MultiTap"); pointerAction.performed += HandlePointerInteraction; }

void OnEnable() { pointerAction?.Enable(); }

void HandlePointerInteraction(InputAction.CallbackContext context) { Debug.Log($"[InputManager Action] Interaction '{context.interaction?.GetType().Name ?? "Press"}' Performed..."); } // this is never executed when tapping

PierreGerbaud avatar Apr 29 '25 12:04 PierreGerbaud

Taps are properly registered by Android Logcat but don't reach Unity.

Confirm. Struggling with the same issue.

sergeymorkovkin avatar May 05 '25 05:05 sergeymorkovkin

Does Unity detect a touch when using the old input system instead of the new Input System package?
You should be able to switch using Active Input Handling in the player settings and updating the eventsystem in your scene.

No

If not, this comment is likely completely off-topic and you can ignore the rest.

Yes

I don't use react-native, but I do use Unity embedded in Flutter.
I ran into the issue that the old input system could receive touches from Flutter, but the new Input System package ignored them.

It ended up being the MotionEvent that Flutter passes on to Unity. The events get sent with deviceId: 0, which makes the input system package discard them. Simply modifying that to any other value made the touch events work.

For Unity 2022 and below you could override this function in UnityPlayer to check and modify touch events.

 override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
       
        // check if mottionEvent.deviceId is 0 here. 

        return super.onTouchEvent(motionEvent)
    }

Unity 6000 makes that harder since they no longer implement FrameLayout.

For reference: https://github.com/learntoflutter/flutter_embed_unity/pull/17

timbotimbo avatar May 16 '25 15:05 timbotimbo