Search Unity

Input.GetAxis("Mouse X") always return 0

Discussion in 'Editor & General Support' started by Juan, May 14, 2012.

  1. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    I'm trying this script
    Code (csharp):
    1.  
    2.  
    3.     void Update () {
    4.    
    5.         if(Input.GetMouseButton(0))
    6.         {
    7.             print(Input.GetAxis("Mouse X").ToString());
    8.             print("check");
    9.            
    10.         }
    11.        
    12.     }
    13.  
    14.  
    And "Input.GetAxis("Mouse X")" always return 0.
    This does not happend under OSX, just if i'm in windows.

    Does someone knows a workaround for this?
    Another option to detect mouse movement?

    Help please.

    Cheers.
     
  2. TheHoboCoder

    TheHoboCoder

    Joined:
    Feb 18, 2012
    Posts:
    33
    I can't use Unity right now but I think that GetAxis("Mouse X") returns only movement of mouse. So if your cursor is "still", it returns 0 and if you move it while you click, it should return something else. Not sure so correct me if I am wrong :S
     
  3. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Even just this:

    Code (csharp):
    1.  
    2.  
    3.  print(Input.GetAxis("Mouse X"));
    4.  
    5.  
    Is returning 0, so Input.GetAxis is not working at all under windows.

    Cheers.
     
  4. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142

    Yes you are correct, the problem is that it doesn't return anything but 0 when my cursor is moving.
     
  5. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Works for me. It shows the mouse acceleration when i'm doing
    Code (csharp):
    1.  
    2. print(Input.GetAxis("Mouse X"));
    3.  
     
  6. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Are you in the latest Unity version?
    What version o windows do you have?

    It worked for me in the past too, but right now it's always 0, no matter if I'm in my main machine with Windows 7 or if I'm under my MacBook pro with parallels or bootcamp, it fails in both machines.

    I'll do a build of the test project and I'll upload here to see if it works for everyone.

    Cheers and thanks for answering.
     
  7. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    Doesn't .ToString cut out the float value? I reckon that since GetAxis ranges 0...1, you never really get 1, so it spits out 0. Try without the .ToString -- it is expendable anyways.

    Input.GetAxis works (Unity3.5) as that is the primary means by which I move a virtual cursor on the screen. Check in the Input Manager if the Mouse X is assigned properly -- maybe something went wrong there?
     
  8. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    It doesn't cut the value, i tried the same under mac and it works.

    Do you work under windows Zethariel? what version? I'm trying to figure if it's related to my windows version :S

    Here you have a build of the test project for windows standalone:

    http://www.bone-studio.com/clientes/juan/unity_bug/project_b.rar

    And here you have a unitypackage with the contents of that project:

    http://www.bone-studio.com/clientes/juan/unity_bug/project.unitypackage

    I tried to check if everything was fine in the input manager, and everything was just fine.

    I tried without .ToString and the value is 0, i noticed that because i use that in my project, i use it to control the orientation of a camera, and under mac it works perfectly, but if i do the a windows build from the mac, or i use it under windows editor (or i do a windows build form windows) It's not working at all.

    I'm using Unity 3.5.1f2 in both, windows and mac and i'm under windows 7.

    Thanks for the answer guys, this is driving me crazy, and it's a pretty basic part of unity, is the only way to get the movement of the mouse!

    Cheers.

    EDIT: By the way, in the build i've posted here i put two labels, one is checking if the mouse button is pressed, and the other is the value of Input.GetAxis, toString don't have to cut it out since the only thing it does is to pass teh float value to a string value, and i used it a lot of times before with other values, you can check it with Input.GetAxis("Horizontal") and using the cursors, and you'll see the float values.
    Cheers :)
     
    Last edited: May 15, 2012
  9. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    I'm using Windows 7, up-to-date. I'll edit this post later on to tell you if your program works (an hour, maybe hour and half, not at my home PC right now).

    This might not be related, but I got some pretty bad compiling errors for my latest project when building a mac friendly version from windows -- my friends reported it was broken to the point of even not displaying any error message, or anything at all. Maybe this somehow applies both ways, but this seems to be a subtler bug?

    EDIT: The .rar version works for me -- when I move the mouse around, I can see the 0 changing according to the speed I am swinging the mouse with. Must be some silly error you're getting :)
     
    Last edited: May 15, 2012
  10. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Thanks Zethariel.

    My builds work fine, the only problem i have is that, i use this just in one part of my app, and what drives me crazy is that it works fine under mac version :S but it doesn't work under windows version (not editor or build).

    I hope i'm doing something really wrong and it's not a bug, just my silly head :p

    Cheers and thanks again.
     
  11. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Zethariel Have you had time to test this?

    Has someone tested this?

    Cheers.
     
  12. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    I've found another script in a website that uses Input.GetAxis

    Code (csharp):
    1.  
    2.  
    3. var speed : int;
    4. var friction : float;
    5. var lerpSpeed : float;
    6. private var xDeg : float;
    7. private var yDeg : float;
    8. private var fromRotation : Quaternion;
    9. private var toRotation : Quaternion;
    10.  
    11. function Update () {
    12.     if(Input.GetMouseButton(0)) {
    13.         xDeg -= Input.GetAxis("Mouse X") * speed * friction;
    14.         yDeg += Input.GetAxis("Mouse Y") * speed * friction;
    15.         fromRotation = transform.rotation;
    16.         toRotation = Quaternion.Euler(yDeg,xDeg,0);
    17.         transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime  * lerpSpeed);
    18.     }
    19. }
    20.  
    21.  
    Here is the site:

    http://answers.unity3d.com/questions/10154/how-can-i-make-a-gameobject-rotate-with-mouse-drag.html

    AND THIS IS NOT WORKING AT ALL!!! IT'S DOING NOTHING!

    Help please Unity staff, this MUST be working, it's a basic thing!
     
  13. Zethariel1

    Zethariel1

    Joined:
    Mar 21, 2012
    Posts:
    439
    As said before, it was fine on my end -- the number changed etc. An extremelly strange error to be honest. Others would have to confirm that it happens only for you. In the meantime, I'd file a bug report with your system specs, the project and what really happens.
     
  14. cod

    cod

    Joined:
    Nov 26, 2011
    Posts:
    267
    maybe normalize the values? So u'll have a 0...1 range :D
     
  15. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Have you tried my build?

    There you'll see if it works when it's executed in your computer or not, and i've uploaded the demo project too so you can see the code and make a build yourself.

    I reported a bug with the test project and i've referenced to this thread, but i didn't received any answer yet :p

    cod: the problem is not the range, the problem is that the mouse movement is not being detected at all, it's always 0 no matter what you do.

    BTW i tested this with 3.5.2 too.
     
  16. cod

    cod

    Joined:
    Nov 26, 2011
    Posts:
    267
    it work perfectly under windows 7 64 bit :D
     
  17. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Ok, i've managed to test the build in another computer (finally) and it works in that computer.

    Is there some kind of incompatibility between Logitech SetPoint and Unity?

    Is the only thing i can think about that may be generating a problem :S
     
  18. Juan

    Juan

    Joined:
    May 21, 2009
    Posts:
    142
    Thanks cod... it should be something related with both of my computers, bootcamp windows (or parallels windows) and my main windows workstation :S
     
  19. HulloImJay

    HulloImJay

    Joined:
    Mar 26, 2012
    Posts:
    89
    Sorry to resurrect the thread, but I have this same issue and I don't see any clear answers here.
    Started with the default MouseLook working in a project on my Mac system but mysteriously not in Windows. I traced it to the GetAxis calls — neither Input.GetAxis("Mouse X") nor Input.GetAxis("Mouse Y") return anything but zero, although these axes appear to be set up correctly in the Input section. (They weren't changed from the defaults, although later I tried boosting the sensitivity just to see if that would help — it did not.)
    I've also been able to use MouseLook previously in Windows (fairly sure), so some conflict has occurred recently for me.

    I tried Juan's build (above) and got a continual display of 0 while moving the mouse.

    Windows 7 64 bit
    Unity 3.5.3f3
    Wacom Intuos4 mouse (latest official drivers)
    Affects both the Web Player build and standalone, and in multiple projects.


    Juan, did you happen to make a bug report on this?
     
  20. HulloImJay

    HulloImJay

    Joined:
    Mar 26, 2012
    Posts:
    89
    Okay!

    I switched mice to a Logitech wireless, and everything works normally. Now, I know that Wacom has some oddities in the way they do mouse drivers, but their mouse works perfectly for other apps, including games. And Juan was using a Logictech mouse with the same issue.

    Perhaps the most recent versions of Unity have developed an odd bug where some mice under Windows don't read properly as axes?

    (Will report this to UT now, but further info anyone can offer would be appreciated.)
     
  21. TerryNorton

    TerryNorton

    Joined:
    Jun 6, 2008
    Posts:
    24
    I'm doing a tutorial over at 3D Buzz. I'm on a MacBook Pro running Unity under Windows 7 in a Parallels virtual machine.

    Input.GetAxis just returns 0.

    On Unity for Mac, Input.GetAxis works perfectly.

    I checked every setting I could find for Unity, Windows 7, Parallels, and OSX,

    I have a Magic TrackPad, Apple mouse, and LogiTech Trackman. Using all 3, Input.GetAxis works in Unity for Mac, does NOT in Unity for Windows.

    However, I have no idea what is causing this issue. Since Unity works fine for those on a PC, and it works fine on a Mac, I tend to think the issue might be Parallels.

    The thing that puzzles me though, is all my input devices work normally in the few apps I run in Parallels. So if the mouse pointer is functioning just fine, then why can't Input.GetAxis see the mouse movements for "Mouse X" and "Mouse Y"?
     
    ElasticSea likes this.
  22. TerryNorton

    TerryNorton

    Joined:
    Jun 6, 2008
    Posts:
    24
    Well, I got this working in Windows 7 running in Parallels.

    In the lower right corner of the Parallels window is a gear to set Windows settings. Click the Options icon, the select Advanced in the left column. The culprit, for me, was the SmartMouse setting.

    With it set to either On or Auto, the mouse reading was always zero.

    When set to Off, it works perfectly.

    When SmartMouse is off, the Windows environment has full control of the mouse, and Unity can read the mouse.
     
    Wisteso likes this.
  23. zhangjiq

    zhangjiq

    Joined:
    May 17, 2012
    Posts:
    17
    Yes , there may be a bug in unity.
    This happened to me when I use a remote desktop in windows.
    I think a virtual machine may have the same issue.
     
    Adil192 likes this.
  24. Brocan

    Brocan

    Joined:
    Mar 22, 2012
    Posts:
    45
    As zhangjiq says, the mouse reading doesn't work with remote desktop, so it's highly possible that virtual machines could have the same issue.
     
  25. tnaseem

    tnaseem

    Joined:
    Oct 23, 2009
    Posts:
    149
    This has been driving me nuts! I've been having the same issues (running a test build under Parallels / Windows 7 64bit).

    Turning off that SmartMouse setting did the trick. Many thanks for the heads up on that, Terry.
     
  26. TerryNorton

    TerryNorton

    Joined:
    Jun 6, 2008
    Posts:
    24
    If it isn't already, this should be listed in a Tips Tricks section.
     
  27. franky303

    franky303

    Joined:
    Aug 27, 2012
    Posts:
    10
    i'm running Windows 7 inside Vmware Fusion on OSX, and i'm experiencing the same problems. - Any solution to this? Really annoying ....
     
  28. franky303

    franky303

    Joined:
    Aug 27, 2012
    Posts:
    10
    FOUND A WORKAROUND FOR VMWARE FUSION ON OSX:

    You need:

    a) an USB mouse, that will be connected directly to the VMware virtual machine
    b) adjust the settings of the virtual machine, so that the mouse is directly connected via USB to windows: to accomplish this, follow the instructions from the vmware knowledgebase:
    http://kb.vmware.com/selfservice/mi...nguage=en_US&cmd=displayKC&externalId=1003418

    Voila! - It's working!
     
  29. JosiahBradley

    JosiahBradley

    Joined:
    Nov 6, 2014
    Posts:
    3
    In case anyone reads this in the future. Using synergy will also result in a constant 0. Networked mice apparently report their positions differently and have no deltas.
     
  30. wangyinxing

    wangyinxing

    Joined:
    Feb 13, 2015
    Posts:
    1
    Yeah.
    I've used synergy and I had same problem like this.
    Please use only directly attached mouse. : )
     
  31. diggerjohn

    diggerjohn

    Joined:
    Apr 28, 2009
    Posts:
    60
    I am having the same problem with my Wacom Intuos Mouse.
    If I use a crummy old USB Mouse .... no problems.
    So it must be the Intuos driver.
     
  32. Matt-Black

    Matt-Black

    Joined:
    Jan 6, 2016
    Posts:
    1
    Resurrecting but I have additional insight for this issue.

    My circumstance: Windows 7 laptop with HDMI external montior, microsoft wireless usb mouse.

    Steps causing issue: When running my game in the editor, Input.GetAxis("Mouse X") controlled the player movement. This afternoon I took my laptop on the road and ran a different game (business as usual). When I got back home I hooked up my laptop but didn't turn on my external monitor (laziness). Opened up the first game that responds to Mouse X and couldn't move the player. I could fire with mouse buttons, but I couldn't move. Huh? So I entered a log statement on the player's update to print Mouse X and found it was returning 0.

    Resolution: Did a search for a potential bug in unity and found this thread. My situation had nothing to do with parallels or remote connection of any type... then for some random reason I turned on my external monitor and found that unity's Game window was moved to the external display (where I had it before I hit the road earlier). I hit play and viola! I've never been more excited to see mouse x delta being returned in the console... bonus: I could play my space invaders clone again!

    Clarification: I continued to experiment with the issue and realized that the external monitor wasn't the true source of the issue. The problem in my case is that when a game tab is dragged out of the editor, it is the only game window that drives the mouse X delta. So, at any time it is not the current window in focus (i.e. clicked on, made the active window) mouse X will always be 0. Furthermore, I tried creating multiple game windows. None of them except the very first one would report mouse x when in focus.

    Sidenote: I would guess that the reason this doesn't happen in Mac OS X, is because mouse input is not always constrained to the most recently clicked on window. One of the many things I love about Macs is that you can scroll through a web page or document without making it "in focus". Handy for homework instead of constant alt-tabbing on Windows.

    Biggest point I'm making: On windows 7 anytime you pull a game window out of the unity editor, make sure you keep it in focus to get proper Input.GetAxis("Mouse X") values (probably Mouse Y as well).
     
  33. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
    Faced with this issue on Win10 + U5.3.4f1.

    It works fine in editor, but breaks in the Win standalone build.

    Interesting though, if open the game with "Fantastic" setting, it would be fine.
    However if open with any setting below "Fantastic", the mouse value will behave badly.

    ===================================

    After more serious checks, I found out that it's the "VSync" option in "Quality" setting,
    In "Good"/"Beautiful"/"Fantastic", VSync is enabled;
    in "Simple"/"Fast"/"Fastest", VSync is disable;

    So I tried enabling VSync in "Simple" and build the player again, this time it works as expected;
     
    Last edited: Mar 31, 2016
  34. Taori

    Taori

    Joined:
    Nov 10, 2013
    Posts:
    1
    U5.3.4f1, VMWare Workstation 12, Windows 8.1 - Same issue here. even when i build the game the only time the axis value is not 0 is when i copy the game and run it on the host. According to search this issue is 4 years old. Please fix it unity...
     
  35. Paul_Bronowski

    Paul_Bronowski

    Joined:
    Sep 3, 2014
    Posts:
    55
    Confirmed. The problem is repro with Unity runtime or Editor, with Windows (10) Remote Desktop. No repro with local execution.
    - thanks
     
    Mile88 and diem389 like this.
  36. TobiasWa

    TobiasWa

    Joined:
    Mar 14, 2016
    Posts:
    5
    I guess there is still no fix? But is there a workaround? I can't switch to my mac for development since I'm developing for Hololens and the SDK is Windows only... Would be great to get a fix for this soon, since this bug is around for a long time now!

    Edit: Just found a workaround: Go to parallels menu --> Devices --> External Devices --> Pick your mouse (I picked the internal mac mouse since the mouse is locked to parallels after you do that... So I'm still able to use my external mouse normally and use the internal trackpad for unity.
     
    Last edited: Aug 9, 2016
  37. TMPxyz

    TMPxyz

    Joined:
    Jul 20, 2012
    Posts:
    766
  38. AndrAla

    AndrAla

    Joined:
    Mar 11, 2017
    Posts:
    18
    I was getting 0 values too until I changed the sensitivity (in the input list) from 0 to 1.
     
  39. ChrisK4242

    ChrisK4242

    Joined:
    Mar 8, 2016
    Posts:
    1
    I'm running Windows 10, Unity 5.6.1f1 and have a Logitech wireless mouse. I was having a similar issue where Input.GetAxis("Mouse ScrollWheel") was returning 0 to the console using Debug.Log. After much searching and some luck I discovered that a scrollwheel system setting change did the trick. Windows -> Settings -> Devices -> Mouse -> Additional Mouse Options (right side of screen) -> Wheel tab and changed Vertical Scrolling, number of lines from 3 to 1. Now I get 0.1 when scrolling the wheel.
     
  40. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    298
    I've been having this issue for about 2 years and I still don't know what's going on or how to fix it. I've literally tried everything and even bought a new mouse to see if that was the issue but it seems it's not. This issue seems to happen randomly also so it's likely Unity themselves aren't even aware of it... I'm glad I switched my Input method because I couldn't rely on Unity's built in input anyways.

    :(
     
  41. MaryamKamel

    MaryamKamel

    Joined:
    Feb 5, 2016
    Posts:
    22
    i had the same problem , so i went to edit>project settings> Input> under Mouse X set the sensitivity to 2 or higher , this should do the trick , i tried it and it worked fine for me (y)
     
  42. rekatha

    rekatha

    Joined:
    Dec 18, 2017
    Posts:
    22
    same problem, Unity 2019. Input.GetAxis("Mouse X") always return 0 if run unity in Windows RDP
     
    mcbauer likes this.
  43. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    524
    Agree with rekatha, still an issue with RDP sessions. Any suggested workaround Unity? Using VM's is pretty commonplace these days.

    I understand the fundemental issue here, there isnt a physical mouse attached but there isn't a physical keyboard attached either but Input.GetAxis("Horizontal") returns just fine.
     
  44. SnooksV3

    SnooksV3

    Joined:
    Dec 11, 2018
    Posts:
    11
    I had this issue, turns out I had set mouse sensitivity via playerPrefs. PlayerPrefs defaulted to zero after a rename of build.
     
  45. cbfunky

    cbfunky

    Joined:
    Sep 11, 2020
    Posts:
    24
    I'm also having this issue (came across this thread googling solutions), not a remote session but I do have a wireless mouse - axis outputs are always 0.
    I did change the sensitivity in the Input Manager (no change). How exactly did you change the sensitivity in playerPrefs? I googled it, but couldn't find anything.

    Has anyone else had any luck finding alternatives? How are you guys controlling your cameras? I essentially can't get a mouse-controlled camera working because of this :'(
     
  46. ai476944298

    ai476944298

    Joined:
    Oct 7, 2018
    Posts:
    2
    Win10 and unity 2020.1.6/2019.3.11, I meet the same question ,a interesting detail is that the API"Input.mousePosition" can work normally but the GetAxis cant work.
     
    Last edited: Sep 28, 2020
  47. PlanCDev

    PlanCDev

    Joined:
    Dec 24, 2016
    Posts:
    2
    I was facing the same problem. Turns out Unity Remote overrides mouse input by default but you can change this behavior by setting Project Settings -> Editor -> Unity Remote -> Joystick Source -> "Local". This solved the issue for me.
     
  48. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    Can anyone file a bug on this?
     
  49. bibbis

    bibbis

    Joined:
    Dec 5, 2016
    Posts:
    58
    Todays date: 2024-01-12
    Unity version: 2022.3.7f1
    I have the same issue as OP described on May 14, 2012.

    Fixed it with PlanCDev's advice:
    Even though there is no remote device connected to my PC and Unity Remote's device option is disabled, this is still an issue.
    upload_2024-1-12_11-49-10.png
     
  50. bibbis

    bibbis

    Joined:
    Dec 5, 2016
    Posts:
    58
    Honestly, can't you do it yourself?
    After people in your community spends countless hours, often over several days, looking for answers to these obscure editor issues, and then countless more hours helping each other figure out how to work around the issues, you can't expect us to have any energy left to ONCE AGAIN, describe and summarize all the steps taken to trigger the issue and all the expected/unexpected side effects.

    You have more than enough information about this issue, conveniently gathered in one single thread spanning 10+ years of information, for YOU to make a damn bug report YOURSELF.
     
    noitomta01 and Freznosis like this.