Search Issue Tracker
By Design
By Design in 2023.1.X
Votes
0
Found in
2019.4.39f1
2020.3.37f1
2021.3.7f1
2022.1.11f1
2022.2.0b3
2023.1.0a4
Issue ID
UUM-10009
Regression
No
Cursor.visible does not take effect when disabling and enabling the GameObject with the Script attached
Reproduction steps:
- Open the attached project
- Open the “/Assets/Qa/Tests/KeyboardMouseBasic/ISX_KB_Mouse_Basic.unity” Scene
- Enter the Play Mode
- Click anywhere in the Game View
- Enable or Disable the “CursorHide” GameObject
- Click anywhere in the Game View
- Repeat the 5 and 6 steps and observe the cursor’s behavior
Expected result: The cursor doesn’t hide after enabling the “CursorHide” GameObject the second time
Actual result: The cursor hides after enabling the “CursorHide” GameObject the second time
Reproducible with: 2019.4.39f1, 2020.3.37f1, 2021.3.7f1, 2022.1.11f1, 2022.2.0b3, 2023.1.0a4
Reproducible on: Windows 10 (21H2), M1 MacOS 12.4 (21F79)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Enabling “Editor Extension Authoring” in UI Builder doesn’t dirty the document and saving with shortcut doesn’t persist the state
- WebRequest.Create() function fails with "URI prefix is not recognized" errors when the project is built for Linux Standalone or Windows Dedicated Server
- “GUIStyle” and “NullReferenceException” errors thrown in the Console when opening Object Field during script compilation
- Reflections are visible on objects without Recursive Rendering when viewed through transparent parts of another object with Recursive Rendering and Alpha Clipping enabled
- Visual artifacts appear when using "clip" method in custom shader and running on GLES
Resolution Note:
I tested the project given but was unable to reproduce the issue. What I saw was that the cursor was hidden in all cases when the Unity Game View had focus (i.e. after clicking in the game view).
It is always hidden because the cursor lock state is set to CursorLockMode.Locked in CursorLock.cs and this will always hide the cursor regardless of the visible state:
https://docs.unity3d.com/ScriptReference/Cursor-lockState.html
https://docs.unity3d.com/ScriptReference/Cursor-visible.html
When I toggled the CursorLockMode.None using the Space bar, then I saw the expected result which was that the cursor was hidden the first time the CursorHide object was enabled and didn't hide on the second or third attempts to enable the component. The Start() function only triggers once, so enabling and disabling the component should not trigger any behaviour in CursorOff.cs or CursorLock.cs a second time.
https://docs.unity3d.com/Manual/class-MonoBehaviour.html
Resolution Note (2023.1.X):
I tested the project given but was unable to reproduce the issue. What I saw was that the cursor was hidden in all cases when the Unity Game View had focus (i.e. after clicking in the game view).
It is always hidden because the cursor lock state is set to CursorLockMode.Locked in CursorLock.cs and this will always hide the cursor regardless of the visible state:
https://docs.unity3d.com/ScriptReference/Cursor-lockState.html
https://docs.unity3d.com/ScriptReference/Cursor-visible.html
When I toggled the CursorLockMode.None using the Space bar, then I saw the expected result which was that the cursor was hidden the first time the CursorHide object was enabled and didn't hide on the second or third attempts to enable the component. The Start() function only triggers once, so enabling and disabling the component should not trigger any behaviour in CursorOff.cs or CursorLock.cs a second time.
https://docs.unity3d.com/Manual/class-MonoBehaviour.html