Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

5.3 - Cursor Disappears

Discussion in 'Editor & General Support' started by JasonBricco, Dec 9, 2015.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I have a cursor texture that I load from the Resources folder at runtime.
    In 5.3, it fails to display at all - for both the default and custom cursor texture.

    I have this code for managing it.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CursorControl : ScriptableObject
    4. {
    5.     private Texture2D cursor;
    6.  
    7.     private void Awake()
    8.     {
    9.         cursor = (Texture2D)Resources.Load("Textures/Cursor");
    10.  
    11.         EventManager.OnUpdate += () =>
    12.         {
    13.             if (Engine.CurrentState != GameState.Playing)
    14.             {
    15.                 if (Cursor.lockState != CursorLockMode.None)
    16.                 {
    17.                     Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    18.                     Cursor.lockState = CursorLockMode.None;
    19.                 }
    20.             }
    21.             else
    22.             {
    23.                 if (Cursor.lockState != CursorLockMode.Locked)
    24.                 {
    25.                     Cursor.SetCursor(cursor, new Vector2(9, 9), CursorMode.Auto);
    26.                     Cursor.lockState = CursorLockMode.Locked;
    27.                 }
    28.             }
    29.         };
    30.     }
    31. }
    That's it. Cursor worked fine pre-5.3. Any idea what's going on here? I don't see anything about Cursor API changes in the upgrade manual.

    Thanks.

    Edit: additional information - I'm running on Mac, El Capitan. This happens both in the editor and in an OS X build.
     
  2. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
    Well thats not fun. Would you be willing to submit a bug report for me? When running Unity choose Help->Report a Bug in the menu. If you post the Bug # here I can keep tabs on it too :D
     
  3. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    After experimenting, it seems to be that setting Cursor.lockState to Locked is what makes the cursor invisible. In my small testing project I made, setting its lock state to None made it visible again. This behavior happened even if I explicitly set Cursor.visible to true after.

    However, in my main project the cursor remains invisible even in my unlocking code shown in my first post.

    I'm not sure if this is a bug or intentional; if it's intentional, it's an inconvenience. I need the cursor locked to the center but still visible.

    I've reported a bug and will post the # here when I figure out what it is.

    Edit: it's 751888.
     
  4. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Additional note: it appears again if I leave focus from the app and come back in. But disappears again as soon as the cursor becomes locked again.
     
  5. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    I realize this is not a true fix, but how about canvas element with cursor graphic that always moves to current mouse x/y? That's how I did it before I knew you can change actual cursor.
     
    JasonBricco likes this.
  6. PsychoDoc

    PsychoDoc

    Joined:
    Apr 28, 2015
    Posts:
    4
    I have the same issue after I updated to 5.3 today... some even seem to have this problem after update 5.2.1f1, as a Help Room request indicates (I updated from 5.1 to 5.3 while skipping 5.2).

    I don't know what keeps disabling the cursor yet. When I run a test script with the code line "Cursor.visible = true;" in the Update() method, however, the cursor reappears, although it's flickering (not meant as a long-term solution, of course). I hope we will find a solution...
     
  7. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    622
    I skipped 5.2 and installed 5.3 yesterday.
    My cursor textures are wrong and almost invisible.
    I have the same bug. Cursor.SetCursor does not work.
     
  8. eelstork

    eelstork

    Joined:
    Jun 15, 2014
    Posts:
    221
    Calling Cursor.visible = true fixes the issue for us (only tested in Unity editor on OS-X El Capitan; issue confirmed but fix not tested yet on Win).

    Sure, looks like a bug.
     
  9. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Setting Cursor.visible to true does work if I call it in an update method to force it true every frame. But this unfortunately causes flickering of the cursor. If I set it once, it didn't work for my case.

    Unity responded to me saying that this was by design and that the documentation would be updated to reflect the new behavior. I can understand setting it invisible to be by design, but setting Cursor.visible to true should be enough to fix it.

    And apparently it is for your case (@eelstork), so that's strange indeed (assuming you only called it once rather than every frame).
     
  10. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    622
    I updated to 5.3.1 and still my cursors are corrupted.Cant find a way to fix this.
     
  11. eelstork

    eelstork

    Joined:
    Jun 15, 2014
    Posts:
    221
    @JasonBrisco as a quirk our code assigns lock state and visibility at every frame - as to why you're seeing flicker I do not know (tried in a sandbox/empty scene?).
    Prior to patching this I remember seeing unpleasant mouse cursor flicker with the same app in previous versions of Unity (on a cheap ASUS 32 bits).

    Not sure at what level I'm understanding hiding upon locking not being a bug (API changes from doing what it says to doing something else?); until I start seeing flickering Santas and reindeers trailing the mouse cursor I can put up with it.