x


Cannot hide mouse cursor anymore

Hi all,

The following code used to work in Unity 3.0 without an issue:

public class Crosshair : MonoBehaviour {

void Start()
{   
    Screen.showCursor = false;
}
void Update()
{
    Screen.showCursor = EngineHelper.Paused;
    Screen.lockCursor = !EngineHelper.Paused;
}

}

But since updating to Unity 3.3 it no longer does. The mouse still locks and unlocks but the cursor flickers on and off.

I have checked in both editor and Windows 7 standalone / web player build with exactly the same result. There is nothing else in my project that is setting the mouse cursor other than this script.

Does anyone know if this is a bug? If so is there a work around?

Thanks in advance.

more ▼

asked May 25 '11 at 03:19 AM

nathanp812 gravatar image

nathanp812
57 6 6 9

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

[edit] [moved up from below] If I build&run the same project, it works perfectly -- no flicker. Problem seems to be only in Play from the Editor.

I've got the same problem with a nearly empty Unity project, nothing else running, on Windows7. Setting Screen.showCursor=false; in Start. Getting a very intermittent flash of the real cursor (a single or double flash every second or two.) Doesn't seem to matter what the mouse is doing.

I'm using a fake guiTexture for the cursor, and changing the texture on that, randomly as a test. Doing or not doing that doesn't seem to affect the flickering at all. Tried moving it across some other guiTextures -- flicker rate unchanged.

One thing that seems to increase flicker rate is Active/Inactive. I'm hiding certain other guiTextures when the cursor is over them, and this seems to reliably cause the "real" cursor to flash on. I move over the guiTexture, my code turns it inactive, and I get extra flickers of the real cursor for the next 1/2-second.

more ▼

answered Feb 03 '12 at 07:15 PM

Owen Reynolds gravatar image

Owen Reynolds
11.4k 1 7 45

This needs to be shown higher on this answer. The flickering DOES NOT happen on the build ONLY in the editor.

Apr 17 at 12:36 PM fafase
(comments are locked)
10|3000 characters needed characters left
  • Are you sure EngineHelper.paused it not the cause, and that the variable is always false when you expect it to be?
  • Have you tried simply using Screen.showCursor = false; to rule out a bug?
  • It could be because you are continuously setting Screen.showCursor, try only setting it if EngineHelper.paused changed. if(!Screen.lockCursor && !EngineHelper.paused) { Screen.lockCursor = true; }else if(!Screen.showCursor && EngineHelper.paused) { Screen.showCursor = true; }
more ▼

answered May 25 '11 at 04:00 AM

Joshua gravatar image

Joshua
6.4k 19 25 70

Hi Joshua,
Thanks for the tips.

Yes, I have tried just setting the Screen.showCursor = false with exactly the same result.

Also have tried only setting these variables inside EngineHelper Pause and Resume methods rather than constantly setting each frame to try and resolve the issue.

I also made sure that the EngineHelper.Paused flag is indeed true when I expect it to be.

The strange thing is that all this worked perfectly until I updated from 3.0 to 3.3.

May 26 '11 at 07:52 AM nathanp812
(comments are locked)
10|3000 characters needed characters left

I had this same problem. My solution was that I had PlayMaker running with "control mouse cursor" checked. I unchecked it and it solved the problem. You may have a similar issue.

more ▼

answered Oct 17 '11 at 06:56 AM

jaybinaryspace gravatar image

jaybinaryspace
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x510
x21

asked: May 25 '11 at 03:19 AM

Seen: 2400 times

Last Updated: Apr 17 at 02:00 PM