Skip to content

NEW: MouseEvents for InputSystem - Sending data from package & Samples and Tests #2207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from

Conversation

ritamerkl
Copy link
Collaborator

@ritamerkl ritamerkl commented Jul 24, 2025

Description

This PR introduces sending pointer data (e.g. mouse, pen, touch...) to native for the OnMouse events driven by the InputSystem. It also adds tests and samples for the OnMouse events working with the InputSystem. The behaviour on native side is introduced with this PR and both PR's should land together, or one (shortly) after the other.

Testing status & QA

Only manual testing for the sample.

Overall Product Risks

  • Complexity: 1
  • Halo Effect: 1

Comments to reviewers

Please review together with https://github.cds.internal.unity3d.com/unity/unity/pull/73198.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@codecov-github-com
Copy link

codecov-github-com bot commented Jul 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff             @@
##           develop    #2207      +/-   ##
===========================================
- Coverage    68.15%   68.15%   -0.01%     
===========================================
  Files          367      367              
  Lines        53662    53586      -76     
===========================================
- Hits         36576    36521      -55     
+ Misses       17086    17065      -21     
Flag Coverage Δ
linux_2021.3_pkg ?
linux_2022.3_pkg ?
linux_6000.0_pkg ?
linux_6000.1_pkg ?
linux_6000.2_pkg ?
linux_6000.2_project ?
linux_trunk_pkg ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../com.unity.inputsystem/InputSystem/InputManager.cs 88.69% <ø> (-0.09%) ⬇️

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@jfreire-unity jfreire-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @ritamerkl ! I like the approach and the sample is of reasonable size to test the main functionality. Also really nice to have plenty of tests.

However:

  • This functionality needs to be guarded with defines in asmdef, as this will only be available from 6.3 forward AFAIK. So if I try this PR without the trunk PR, I'll get compilation errors.
  • I would like to see at least 1 test with Touch as well, particularly with more than 1 touch. Mouse and Pen are pretty similar as they are a single pointer.

@jfreire-unity
Copy link
Collaborator

Nice work @ritamerkl ! I like the approach and the sample is of reasonable size to test the main functionality. Also really nice to have plenty of tests.

However:

  • This functionality needs to be guarded with defines in asmdef, as this will only be available from 6.3 forward AFAIK. So if I try this PR without the trunk PR, I'll get compilation errors.
  • I would like to see at least 1 test with Touch as well, particularly with more than 1 touch. Mouse and Pen are pretty similar as they are a single pointer.

Also there's some CI failures that will need to be addressed. Not sure if it's only because of the lack of defines or if there's any impact on pointer devices functionality.

@ritamerkl
Copy link
Collaborator Author

ritamerkl commented Jul 25, 2025

WIP: working on adding touch samples (multi-touch) & parallel pointers (eg. touch&pen).

Copy link
Collaborator

@LeoUnity LeoUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great!
I'm happy to see us improving our feature parity! Also thanks for investing the time on the tests!
I've left a few comments, but I'll leave it up to you to decide which ones to address

x = Pointer.current.position.x.value;
y = Pointer.current.position.y.value;
}
else // Fallback to InputManager if InputSystem is not available
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support InputManager on this tests? I would assume they are covered by their original tests in trunk...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason why this would use InputManager similar to Leo, I would additionally recommend to rename this script to OnMouseEvents, or MouseEvents or similar. The Test suffix got me thinking I was going to see a NUnit test file or similar

[Category("MouseEvents")]
public IEnumerator PenEvents_CanReceiveOnMouseDown()
{
var pen = InputSystem.AddDevice<Pen>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we are duplicating the exact same tests for both mouse and pen, I'm wondering if we can parameterize that and just have a single test...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree to previous comment, this isn't necessarily the case any longer either right? "That we have to queue into NativeInputRuntime"?

@@ -0,0 +1,4215 @@
{ "pid": 11157, "tid": -1, "ph": "M", "name": "process_name", "args": { "name": "il2cpp-compile" } },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the untitled folder doesn't need to be included?

@ritamerkl ritamerkl changed the title NEW: MouseEvents for InputSystem Samples & Tests NEW: MouseEvents for InputSystem - Sending data from package & Samples and Tests Aug 22, 2025
Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 3 files under "untitled folder", the folder including those files should be removed from this PR right?

@@ -3646,6 +3647,9 @@ private unsafe void OnUpdate(InputUpdateType updateType, ref InputEventBuffer ev
//// mess in the event buffer
//// same goes for events that someone may queue from a change monitor callback
InvokeAfterUpdateCallback(updateType);
//send pointer data to backend for OnMouseEvents
if (Pointer.current != null && gameIsPlaying)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritamerkl Have you checked if Input Manager supports OnMouseXXX events from a script that is marked with [ExecuteInEditorMode]? That could be relevant here...

@@ -3646,6 +3647,9 @@ private unsafe void OnUpdate(InputUpdateType updateType, ref InputEventBuffer ev
//// mess in the event buffer
//// same goes for events that someone may queue from a change monitor callback
InvokeAfterUpdateCallback(updateType);
//send pointer data to backend for OnMouseEvents
if (Pointer.current != null && gameIsPlaying)
NativeInputSystem.SetMouseEventsData(Pointer.current.press.isPressed, Pointer.current.press.wasPressedThisFrame, Pointer.current.position.x.value, Pointer.current.position.y.value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be routed via INativeInputRuntime interface and its NativeInputRuntime and TestInputRuntime implementations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants