Search Unity

[WebGL only] [Input System 1.1.1] Scrolling changes the mouse position with canvas margins

Discussion in 'Input System' started by poprev-3d, Dec 2, 2021.

  1. poprev-3d

    poprev-3d

    Joined:
    Apr 12, 2019
    Posts:
    72
    Using the Input System 1.1.1 with Unity 2021.2.2f1 in WebGL I found a very annoying bug that provokes an offset on the mouse position.

    To reproduce:
    1. Create an empty Unity 2021.2.2f1 WebGL project
    2. Setup a basic implementation of the Unity Input System v1.1.1 (Add a PlayerInput monobehaviour on a GameObject of the scene, setup the default Actions asset and generate the C# scripts for it, that I called TestInputs)
    3. Setup the following script in the scene to debug the mouse position. You shouldn't have to create the Input Actions as those are the default ones included in the default Action assets.

    Code (CSharp):
    1. public class MyTest : MonoBehaviour
    2. {
    3.     // The unity auto-generated script to the input action
    4.     public TestInputs inputs;
    5.  
    6.     void OnEnable()
    7.     {
    8.         inputs = new TestInputs();
    9.         inputs.Enable();
    10.     }
    11.  
    12.     void Update()
    13.     {
    14.         Vector2 mousePosition = inputs.UI.Point.ReadValue<Vector2>();
    15.         Vector2 scroll = inputs.UI.ScrollWheel.ReadValue<Vector2>();
    16.         Debug.Log("Mouse position is " + mousePosition.x + " " + mousePosition.y + " and scroll value is " + scroll.x + " " +scroll.y);
    17.     }
    18. }
    4. Build targetting WebGL. Make sure you use the default template.
    5. Open the WebGL build. Open the browser console.
    6. Finally: Place your mouse somewhere. The mouse position should appear in the console. Then scroll with your mouse and you will notice that the mouse position will be offset but the mouse didn't move (nor did the page scroll). This offset corresponds to the web page margin (a, b) of the player canvas, as shown below.



    As anyone encountered this issue? I tried to reproduce it with the old input system and it doesn't occure.
     
    felipelcunha89 likes this.