Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Mouse Y Position Inverted in Build using Mouse.Current.WarpCursorPosition

Discussion in 'Input System' started by azilorn, May 22, 2019.

  1. azilorn

    azilorn

    Joined:
    Oct 9, 2014
    Posts:
    1
    My code works in editor perfectly fine for navigating around my UI gameObjects using;

    Code (CSharp):
    1. Mouse.current.WarpCursorPosition(gameObject.transform.position);
    but when built the Y axis is inverted for the WarpCursorPosition. Is this something wrong with the New Input system??

    In Editor


    in Build

     
    coolnishd2010 likes this.
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    This sounds like a bug. Which platform is this? Could you report a bug on fogbugz or github with a repro project, and post the case number here?
     
  3. Asidun

    Asidun

    Joined:
    Jun 16, 2018
    Posts:
    1
    I just ran into this same problem. Here is a temporary solution if you're looking for a quick fix:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. #else
    3.     mousePosition.Set(mousePosition.x, Screen.height - mousePosition.y);
    4. #endif
    5.  
    6. Mouse.current.WarpCursorPosition(mousePosition);
     
    azmi_unity and rboerdijk like this.
  4. rboerdijk

    rboerdijk

    Joined:
    Aug 4, 2018
    Posts:
    96
    I just ran into this exact same problem when I ran into this post confirming my suspicion. So for the record, this issue is still present in Input System 1.1.0 preview 2 using Unity 2019.4.8f1 on Windows.
     
  5. IsometricBacon

    IsometricBacon

    Joined:
    Sep 28, 2017
    Posts:
    29
    Issue still exists in 1.02.

    I'm not sure if it's because I'm reversing some pointer inputs in other action maps - but it does it on direct calls to Mouse.current.position which is very strange.
     
  6. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Same problem here , I'm using Unity 2020.3.0f1 with input system Version 1.0.2 - January 21, 2021

    My code :
    Code (CSharp):
    1.     void SetCursorController()
    2.     {
    3.         Mousepos = Mousepos + movementJoyL * CursorSpeed;
    4.         Mouse.current.WarpCursorPosition(Mousepos);
    5.     }
     
  7. eron82

    eron82

    Joined:
    Mar 10, 2017
    Posts:
    83
    Same proble here, version 1.0.2. The temporary solution of Asidun works in full screen only on Mac
     
  8. trcxr

    trcxr

    Joined:
    Jun 16, 2015
    Posts:
    1
    Same Problem here, version 1.0.2. Was anyone able to figure this out?
     
  9. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    Same problem here, version 1.0.2 @ 2021.1.4f1. Solution by Asidun works on Windows build, fullscreen and windowed.
     
  10. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    always the problem here
     
  11. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    If anyone's having a problem, you may want to file a bug report, otherwise Unity probably won't fix it.
     
    Last edited: Jun 8, 2021
  12. EMOTION-THEORY

    EMOTION-THEORY

    Joined:
    Jul 16, 2013
    Posts:
    83
    Same problem here. On builds, the Y-axis of the mouse is inverted.

    This actually made me cry "oh no...!". My experience with the new Input System is just one head-hitting wall to another :(

    To all those struggling though, I can confirm this solution works (thank you Asidun <3)

    If you're using the VirutalMouseInput.cs file from the virtual mouse sample, then add this at the end of the
    UpdateMotion()
    function

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. #else
    3.     newPosition.Set(newPosition.x, Screen.height - newPosition.y);
    4. #endif
    5. m_SystemMouse?.WarpCursorPosition(newPosition);
    6.  
    Here is Asidun's initial comment with the solution.

     
    imaginationrabbit and shuskry like this.
  13. Mokofr

    Mokofr

    Joined:
    Jul 23, 2013
    Posts:
    10
    I am struggling with this problem for a long time now and this added code doesn't seem to do it for me :(

    What else could it be?

    Like I try this code:
    Code (CSharp):
    1. Mouse.current.WarpCursorPosition(new Vector2(1280,300));
    Fine in unity, flipped in the standalone.

    What exactly is the Virtual Mouse? Maybe I am just using a standard mouse?
     
    gamingzombiestudios likes this.
  14. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    I believe a fix for this is making its way through the pipes. Was a problem in the native code not handling Y correctly.
     
  15. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Quick update, Windows editor fix landed it latest 2020.3, 2021.1, 2021.2 and 2022.1, the 2019.4 release is still pending.
    macOS editor fix is still pending.
     
    DomKonecny likes this.
  16. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Just hit this bug in 2019.4 LTS- I can't believe this made it into the example files for the new input system :eek: Didn't anyone test it in a build? o_O

    I used the solution posted here and the y position is no longer inverted but now selecting items with the cursor is very buggy and difficult to do. Seems like the active area/hotspot on the cursor is not consistent.

    I also own Rewired and it includes a sample scene where the Gamepad controls the cursor- just tested it and it works perfectly in the Editor and in Builds- back to Rewire for me.
     
    Last edited: Sep 18, 2021
  17. danielwilkins

    danielwilkins

    Joined:
    Feb 27, 2019
    Posts:
    17
    The macOS editor issue isn't just that the y position is inverted. Even when subtracting the y position from the screen height, it still is offset a bit, perhaps by the cursor height as well. Hope that this is also considered in the next release.
     
  18. danielwilkins

    danielwilkins

    Joined:
    Feb 27, 2019
    Posts:
    17
    Still not fixed on macOS editor as of 2020.3.20f1. Any eta on a fix?
     
  19. danielwilkins

    danielwilkins

    Joined:
    Feb 27, 2019
    Posts:
    17
    Bump. Interested if this has been fixed.
     
  20. danielwilkins

    danielwilkins

    Joined:
    Feb 27, 2019
    Posts:
    17
  21. Kreyg

    Kreyg

    Joined:
    Dec 31, 2012
    Posts:
    45
    Still exists in Unity 2021.1.3f1 using Input Package 1.4.3.
     
  22. AuduneGames

    AuduneGames

    Joined:
    Jul 8, 2019
    Posts:
    1
    I've implemented this workaround in Unity 2020 and have now upgraded my project to Unity 2021.3.11f1, and in my build the y component of the cursor now is inverted with the workaround. When I remove the flipping in my code, it works as intended, so it looks like this issue has been resolved recently. I'm using the Input System package with version 1.4.3.