Search Issue Tracker

By Design

Votes

1

Found in

2018.4

2019.4

2020.3

2021.1

2021.2

2021.2.0a16

Issue ID

1338147

Regression

No

Cursor.visible equals True, while the cursor is invisible when entering Game View after unfocusing it

Scene/Game View

-

Reproduction steps:
1. Open user's project "Cursor bug report.zip"
2. Open "SampleScene" Scene
3. Enter Play Mode and click anywhere in the Game View
4. Notice how the console is logging out "Cursor visible:False, lockState:Locked" and the cursor is invisible
5. Press Esc to unfocus from the Game View, notice how the cursor is visible and the console is logging out "Cursor visible:True, lockState:Locked"
6. Press anywhere in the Game View again

Expected result: Cursor is invisible and the console logs out "Cursor visible:False, lockState:Locked" when entering Game View again
Actual result: Cursor is invisible while the console logs out "Cursor visible:True, lockState:Locked" when entering Game View again

Reproducible with: 2018.4.35f1, 2019.4.27f1, 2020.3.11f1, 2021.1.9f1, 2021.2.0a18

Reproducible on macOS and Windows

  1. Resolution Note (2021.2.X):

    This behavior is by design. As stated in the Cursor.visible documentation, "Set [Cursor.visible] to true to reveal the cursor. Set it to false to hide the cursor. Note that in CursorLockMode.Locked mode, the cursor is invisible regardless of the value of this property."

    The user report requests "a more clear way to identify whether user pressed escape and gameview lost focus", this may be considered as a feature in the future.

Comments (1)

  1. _geo__

    Oct 02, 2025 15:54

    For those in need. Here is a class that you can use to re-capture the cursor even in the editor automatically (though use with caution):
    https://gist.github.com/kamgam/856cdfc03ae14b11d18bf64b3f3fc9e6

    #if UNITY_EDITOR
    using UnityEditor;
    using System.Reflection;

    /// <summary>
    /// Allows the game code for a short time to override the cursor lock behaviour even in the editor.
    /// Usage:
    /// // Call it like this after some input that should trigger capturing the cursor again.
    /// #if UNITY_EDITOR
    /// ForceGameViewCursorLock.AllowCursorLockOverrideForNSec(0.1f);
    /// #endif
    /// </summary>
    [InitializeOnLoad]
    public static class ForceGameViewCursorLock
    {
    private static double s_overrideUntil;

    private static EditorWindow s_gameView;
    public static MethodInfo s_allowCursorLockMethod;

    static ForceGameViewCursorLock()
    {
    System.Type gameViewType = typeof(Editor).Assembly.GetType("UnityEditor.GameView");

    EditorApplication.update += onEditorUpdate;
    }

    public static void AllowCursorLockOverrideForNSec(double seconds)
    {
    s_overrideUntil = EditorApplication.timeSinceStartup + seconds;
    }

    private static void onEditorUpdate()
    {
    bool isAllowed = EditorApplication.timeSinceStartup < s_overrideUntil;

    if (!isAllowed || !EditorApplication.isPlaying || EditorApplication.isPaused)
    return;

    // Cache reflections
    if (s_gameView == null &&
    EditorWindow.focusedWindow != null &&
    EditorWindow.focusedWindow.GetType().Name == "GameView")
    {
    s_gameView = EditorWindow.focusedWindow;
    s_allowCursorLockMethod = EditorWindow.focusedWindow.GetType().GetMethod("AllowCursorLockAndHide", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
    }

    // Enable
    if (EditorWindow.focusedWindow == s_gameView && s_gameView != null && s_allowCursorLockMethod != null)
    {
    UnityEngine.Debug.Log("override");
    s_allowCursorLockMethod?.Invoke(EditorWindow.focusedWindow, new object[] { true });
    }
    }
    }
    #endif

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.