Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Can't hide the cursor

Discussion in 'Input System' started by tertle, Jan 4, 2019.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    For some reason, when I switch Active Input Handler from Input Manager to Input System I can no longer hide the cursor.

    Even setting this every frame does not hide it.

    Code (CSharp):
    1. Cursor.lockState = CursorLockMode.Locked;
    2. Cursor.visible = false;
    The cursor just sits in the middle of screen vibrating a little before snapping back when I move the cursor.

    Tested both in editor and at run time on windows. 2018.3f2
     
  2. Weird, I have just tested and I do not experience the problem. It may have some other cause. (I set both the lockState and the visible in Awake)
    Also tried with "Input System" and with "Both" setting.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    I checked the entire project, no other use of lockstate or visible anywhere so I don't know what is up.

    It was working fine before I switched over so not sure what else could be the cause.
     
  4. Input version? I have the latest I can see: 0.1.2-preview.
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    0.1.2-preview

    I don't really know why this would cause the issue, the input manager doesn't seem responsible for the unity cursor behavior.
     
  6. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Ok, definitely something to look at. The Cursor API should be unaffected by that switch but could well be there's something we missed. Filed a ticket here.
     
  7. Schreilem

    Schreilem

    Joined:
    Jun 1, 2018
    Posts:
    1
    Hi!

    Sorry for reviving this thread, but I'm still facing this problem. I'm using Unity 2019.4.6f1 and the New Input System version 1.0.0.

    When setting the player settings to use only the New Input System, the cursor remains visible, no matter if I put the Cursor.visible = false and Cursor.lockState = CursorLockMode.Locked. However, if I change the player settings to use both inputs, the cursor's visibility works as it has to.

    Is there any way to fix this using only the new input system?

    Thank you very much!
     
    bruceweir1 likes this.
  8. treecki

    treecki

    Joined:
    Feb 6, 2017
    Posts:
    29
    @Schreilem I'm running into a similar issue, I tried generating a custom transparent texture to "hide" the cursor but that ended up just creating a all black texture on the mouse. I looked into the bug report and its says fixed in 2020.1... which is not useful as I can't update my project past 2019 for now. How did you end up setting unity to use both inputs? That seems to be the only solution for now...
     
    maclark86 likes this.
  9. HunterAhlquist

    HunterAhlquist

    Joined:
    Oct 6, 2013
    Posts:
    131
    Still having this issue in 2020.1.4f with the new input system 1.0.0
     
  10. HunterAhlquist

    HunterAhlquist

    Joined:
    Oct 6, 2013
    Posts:
    131
    My dirty and wasteful work around is to run Cursor.visible = false; every frame.

    EDIT: This method is very flaky and suddenly stopped working.
     
  11. kakojara

    kakojara

    Joined:
    May 18, 2014
    Posts:
    1
    Hi, I have a workaround for this. It's not ideal, but it kinda works. Just customize the cursor image to a null texture. Like this line:

    Code (CSharp):
    1. Cursor.SetCursor(null,Vector2.zero,CursorMode.Auto);
    Obviously you don't have to call it every frame so it's not terrible, but as I said, not ideal, and you should remember to set a sprite when you actually need the cursor again. Hope it helps!
     
    MonkeyPuzzle likes this.
  12. laessnb

    laessnb

    Joined:
    Jun 10, 2014
    Posts:
    101
    Confirming this is still broken. InputSystem v1.1 on Unity 2019.4. No matter what I do, the hardware cursor stays visible, unless I toggle Both for input system usage.
     
  13. DrSeltsam

    DrSeltsam

    Joined:
    Jul 24, 2019
    Posts:
    101
    Can confirm. The issue is tracked here btw: https://issuetracker.unity3d.com/is...ot-work-when-inputsystem-package-is-installed

    In editor, I can get the cursor visibility to work properly in most cases if I move it into the game view window immediately after hitting the play button.
    In builds, however, cursor visibility seems to be broken in most cases (i.e. always visible) - especially when the game runs in windowed mode.

    This issue is quite frustrating (I wouldn't care that much about the editor, but it's annoying that this also happens in builds). Are there any news about this issue @Rene-Damm ?
    I'm using Unity 2020.1.11f1, Input System 1.1.0-preview.2 (but this bug was also present in the verified 1.0.0 package), HDRP 8.2 and the latest UI Toolkit package, just in case this matters...
     
  14. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    It works if I do it like this. (in editor, haven't tried build)


    private IEnumerator HideCursor() {
    yield return new WaitForSeconds(3);
    Cursor.visible = false;
    Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    }


    Removing the visible = false breaks it again.
    Then I call Cursor.visible = true; when the mouse moves and the mouse is back for some reason.

    The odd thing is that setting the cursor to null just means you're using the default cursor texture.
    But what ever it works I guess.
     
  15. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    I am also getting this bug. Seems strange this hasn't been fixed yet.
     
  16. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    It's added to the known issues in the latest unity 2019 release notes though.
     
  17. Qhuhuit

    Qhuhuit

    Joined:
    Feb 17, 2018
    Posts:
    39
    None of theses workaround are working in the editor for me, @lejean code made the cursor invisible while over the game windows but didn't locked it in.
    Adding ```Cursor.lockState = CursorLockMode.Locked;``` did the trick though !
    Code (CSharp):
    1. void Awake()
    2.     {
    3.         StartCoroutine(DelayedLockMouse());
    4.     }
    5.    
    6.     IEnumerator DelayedLockMouse()
    7.     {
    8.         yield return new WaitForSeconds(1f);
    9.         Cursor.visible = false;
    10.         Cursor.SetCursor(null,Vector2.zero,CursorMode.Auto);
    11.         Cursor.lockState = CursorLockMode.Locked;
    12.     }
     
    MintBlast likes this.
  18. IgnisIncendio

    IgnisIncendio

    Joined:
    Aug 16, 2017
    Posts:
    223
    This doesn't seem to work for me either. It locks the cursor, visibly to the center after 1 second. What does work for me however, is clicking the game view before Cursor.visible is called. This code does help with that (by giving me a 1 second window).
     
  19. Nova1824

    Nova1824

    Joined:
    Sep 25, 2020
    Posts:
    10
    I'm experiencing a similar problem but this time it is with setting the Cursor.lockState to CursorLockMode.Locked. In an empty 2019.4 project I have tested a simple script attached to the main camera that sets the lock state in Update(), but the cursor is free to move. I've tested this in the editor as well as the built version of the project. I have replicated the bug on two machines. Am I missing something about how this feature is suppose to work or be set up?
     
  20. QBrute

    QBrute

    Joined:
    Jun 2, 2014
    Posts:
    3
    I have the exact same problem with 2020.3.01f. I filed a bug report and started a Reddit thread here: https://www.reddit.com/r/Unity3D/comments/m4j02d/latest_lts_release_202030f1_and_cursor_locking/
     
  21. Nova1824

    Nova1824

    Joined:
    Sep 25, 2020
    Posts:
    10
    After closing unity and restarting it the next day, the strange mouse behavior went away. It now works as intended. Strange bug. I can't seem to replicate it now and I did nothing that would have caused it to suddenly work. Idk guys.
     
  22. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Sorry to revive this thread again but this bug has happened to me, i'm using Unity 2019.4.8f1 I've asked in the Unity forum, no answer, brackeys discord server and no answer. it's getting annoying, if anyone has a fix for this please post.
     
  23. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    There is no fix afaik, it's been in the known bugs for the last 3-4 unity 2019 LTS updates. Just gotta wait
     
    Corrothon likes this.
  24. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    Alright thanks
     
  25. jazzy-rey

    jazzy-rey

    Joined:
    May 27, 2017
    Posts:
    2
    all the LTS Versions are broken, this is a big disappointment im just wasting my time day by day this issue still happening in 2020.3.16f1 LTS today
     
    Predulus and freb97 like this.
  26. Corrothon

    Corrothon

    Joined:
    Jun 11, 2019
    Posts:
    60
    What I did to fix it months ago, I had bought playmaker a day before and then randomly thought that might help me hide the cursor, so I imported PlayMaker to my game and all I had to do was to add a hide cursor script from there.
     
  27. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    The issue linked above states that this is fixed in 2019.4.30f1. I was experiencing this bug after switching to the new Input System, but I was on 2019.4.29f1 at the time. I've just updated to 2019.4.30f1, and it does indeed seem to be fixed.
     
  28. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    90
    This is still a problem for me in 2022.1.0a13.1822 .

    How can something so fundamental be a problem for so many years? It's this kind of thing that makes me lean towards using a more polished platform like Unreal. So annoying.
     
    Areltoid likes this.
  29. Predulus

    Predulus

    Joined:
    Feb 5, 2018
    Posts:
    90
    @Rene-Damm what's the deal with this? I could not find the ticket you posted above, which leads me to think Unity thinks they have fixed the problem, which is not the case, at least not comprehensively. Please raise again urgently, this is a long-term problem of something very fundamental. It reflects badly on Unity as a company.
     
  30. gareth_untether

    gareth_untether

    Joined:
    Jan 5, 2018
    Posts:
    69
    Same on 2021.2.10f1
     
    Predulus likes this.
  31. Hafazeh

    Hafazeh

    Joined:
    Mar 26, 2017
    Posts:
    18
    has this issue been fixed?
     
    Predulus likes this.
  32. toddw

    toddw

    Joined:
    May 9, 2010
    Posts:
    130
    Wow this is nuts, I'm still on 2020.1.2f1 because I don't want to deal with guaranteed headaches that occur upgrading to latest unless it will solve something important. This cursor issue that brought me to this thread is one such thing and yet from what I'm reading here, this is a known bug that was reported two years ago, never fixed and then swept under the rug. Truly mind boggling that Unity would leave it this way.

    For those of you that may find this useful since Unity is obviously never going to fix it... this worked for me for the most part, however, it's not perfect as the cursor still flickers on and off a bit during loading screens that are locking up the UI thread, but when the game is running a smooth frame rate I'm not seeing the cursor at all.

    Code (CSharp):
    1.    
    2. private void OnGUI()
    3.     {
    4.         Cursor.visible = false;
    5.     }
    6.  
     
  33. zibolo

    zibolo

    Joined:
    Jun 10, 2015
    Posts:
    1
    This might help some: I had the same problem, but realized that I needed to click on the play screen in play mode for the cursor to actually disappear (still needed to add the "HideCursor" script though)
     
    WidmerNoel likes this.
  34. WidmerNoel

    WidmerNoel

    Joined:
    Jun 3, 2014
    Posts:
    65
    If you set Cursor.isVisible = false; then this will only work in the editor if you click into the game tab after the game has started. It will however work as expected once you run the built game outside the editor.
     
    nimeMotion and Hines94 like this.
  35. Riptide559

    Riptide559

    Joined:
    Feb 1, 2020
    Posts:
    9
    2021.3 - it's occurring for me.
     
  36. JonathanCel

    JonathanCel

    Joined:
    Feb 17, 2021
    Posts:
    22
    I'm having the opposite issue in 2021.3

    I hit Esc from the First Person Controller (yes, I know it's awful), and the mouse becomes visible.
    It's still getting the OnLook() calls though, so if I move to the scene view, I lose whatever I was looking at.

    When I check, I get:

    Cursor.visible = true
    Cursor.lockState = Locked


    Regardless of whether the mouse is actually visible.
    (In fact, regardless of what window has focus)

    I just want to check if the mouse is visible, and if so, disable input.

    Notes:
    -There are no other Cursor.visible calls, etc that I can see.
    -The input system asset settings are not appropriate here (and don't respect focus)
    -I've restarted the editor several times.

    Any hints?
    Cheers.


    You've been here 12 years, how have you not come to expect this! :D
     
  37. rainwizerd

    rainwizerd

    Joined:
    Feb 19, 2020
    Posts:
    7
    Any news on this? Still broken in 2021.3.20f1... Cursor.visible does not work.

    EDIT: This seems to be an editor only issue, as it works properly in builds for me.
     
  38. Dragnil_7

    Dragnil_7

    Joined:
    Jan 26, 2022
    Posts:
    2
    For me its not even on the editor :(
     
  39. nimeMotion

    nimeMotion

    Joined:
    Aug 3, 2019
    Posts:
    3
    Thaks a lot!!!!! it works for me just fine, i'm using 2021.24f1
     
  40. logodotdesign

    logodotdesign

    Joined:
    Oct 2, 2023
    Posts:
    1
    i want when player press m Cursor.visible = true and when he press m again Cursor.visible = false
    can you help me?❤️
     
  41. tujh2100

    tujh2100

    Joined:
    Aug 20, 2023
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class NewBehaviourScript : MonoBehaviour
    {
    public static bool signal;

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.M))
    {
    if (signal)
    {
    Cursor.visible = false;
    signal = false;
    }
    else
    {
    Cursor.visible = true;
    signal = true;
    }
    }
    }
    }

    I don't know if it works or not, but in theory it should work.
     
  42. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    713
    2022 LTS this is still happening to me....
     
  43. HeizenblogGaming

    HeizenblogGaming

    Joined:
    Jun 12, 2016
    Posts:
    10
    Still happening, and using the latest LTS version 2022.3.19f
     
    rmele09 likes this.
  44. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    713
    Its so ridiculous lol
     
  45. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    345
    Happened to me with Unity 2022.3.20f1
    I rolled back the Unity Input system from 1.7 to:
    "com.unity.inputsystem": "1.6.3",

    and now it works correctly again.
     
    rmele09 likes this.
  46. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,061
    Is anyone still working on this thing? Surely Unity, the multibillion company, has enough resources to issue a hotfix to a package literally all Unity projects need. Last update was in August 2023? Why?
     
    rmele09 likes this.
  47. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    713
    it's so crazy to me
     
  48. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 5, 2024
    Posts:
    458
    They do work on this thing, but not on things people actually need. They are working on an unstable new settings window for some unknown reasons.
    https://forum.unity.com/threads/pro...ted-new-update-released.1488843/#post-9641759