Search Unity

Cursor Lock Mode Locked not working in WebGL build

Discussion in 'Web' started by helikaon00, May 14, 2022.

  1. helikaon00

    helikaon00

    Joined:
    Feb 20, 2018
    Posts:
    3
    I'll start by saying, it IS working in the editor.

    I am using a UI button click to set lock the cursor mode.

    That's it. UI Button has onClick calling a function that locks the cursor.

    It doesn't work in WebGL, it works in the editor.

    Why?

    Here is the function you can test yourself in WebGL.


    public void STUPIDTEST()
    {
    Cursor.lockState = CursorLockMode.Locked;
    }
     
    Last edited: May 14, 2022
  2. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    273
    What version of Unity are you using? We've been fixing a lot of input related bugs from 2021.2 onwards.
     
  3. giuseppecassisi25

    giuseppecassisi25

    Joined:
    May 2, 2022
    Posts:
    1
    I have the same problem... The mouse is locked correctly in the editor but in the WebGL build is locked in the last position of the mouse and not in the center. My unity version is the 2020.3.20f1. I set the cursor lock mode like this:

    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
     
  4. umbrella-crash

    umbrella-crash

    Joined:
    Mar 3, 2022
    Posts:
    20
    I am also having this problem. Is there any workaround?
    Possibly useful clue: I've noticed that it works in the WebGL build if I open the browser's web development tools! Once I've opened that, the cursor locking works perfectly. So far I've tried this in Firefox and Edge. Obviously, this is not a workaround for actual players, but maybe it is a clue about what is going wrong?
     
  5. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    273
    The incorrect mouse position when the cursor is locked was a known bug that I fixed in 2020.3.28f1, 2021.2.0b10.3401, and 2022.1.0a7.975. Please upgrade to one of those and you should see the mouse position correctly in the middle.
     
  6. KingSlayer5986

    KingSlayer5986

    Joined:
    Mar 29, 2023
    Posts:
    2
    I have the same problem, I also used the same lines of code as giuseppecassisi25 stated above. Does anyone have a fix? I was using unity 2022.2.17f1 but then switches to 2020.3.28f1 to see if it works and it still doesn't
     
  7. electorchstrauss

    electorchstrauss

    Joined:
    Mar 13, 2021
    Posts:
    11
  8. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    electorchstrauss likes this.
  9. electorchstrauss

    electorchstrauss

    Joined:
    Mar 13, 2021
    Posts:
    11
    Whoa nice catch thanks, edited my comment