x


Mouse Input Lag

I'm using a simple script to replace the windows cursor with a custom one. However, before turning the windows cursor off, I noticed that my cursor lags behind it when I move the mouse. It's not gamebreaking, but it's annoying.

var cursorTexture : Texture;

function OnGUI() {

     GUI.DrawTexture(Rect(Input.mouseposition.x, (Screen.height - Input.mousePosition), 64,64), cursorTexture);

}

I doubt it's related to performance considering I'm testing this on a scene that only contains a Camera (with this script attached, of course).

Is this one of those things that are hard-coded into the engine or is there an alternative method that yields no lag?

Thank you.

more ▼

asked Dec 07 '11 at 10:58 PM

OCASM gravatar image

OCASM
1 1 1 1

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

2 answers: sort voted first

The OnGUI() function is known to be slow. Unity 3.5 will hopefully have an improved GUI system.

But, I do not think it is the slowness of this function that is causing the issue.

I do think that it is a performance issue but not what you are thinking of. The OnGUI() function might not be called every frame which would cause that lag. You might be able to use GUITexture for no lag.

Of course, when you hide the Windows cursor, the lag would barely become noticeable.

more ▼

answered Dec 07 '11 at 11:59 PM

rabbitfang gravatar image

rabbitfang
912 2 4 11

Thank you for your reply.

I added a GUITexture to the scene with the following script

var textureSize : int = 64;

function Update(){

    guiTexture.pixelInset = Rect (Input.mousePosition.x - textureSize/2, Input.mousePosition.y - textureSize/2, 64,64); 

}

Seemed just as laggy. Perhaps the problem is with how the mouse input is recorded by the engine, who knows.

Dec 08 '11 at 08:49 AM OCASM
(comments are locked)
10|3000 characters needed characters left

After checking you Cursor position code, i'd say you better use Update() to update cursor postion and OnGUI() only to display it. That way you delete the lag caused by OnGUI calls.

more ▼

answered Dec 08 '11 at 09:38 AM

ks13 gravatar image

ks13
264 13 15 17

I tried using a separate GUITexture with the following script:

var textureSize : int = 64;

function Update(){

    guiTexture.pixelInset = Rect (Input.mousePosition.x - textureSize/2, Input.mousePosition.y - textureSize/2, 64,64); 

}

As you see, it's all done in Update() and sadly the lag persists, so it may be an engine issue after all.

Thank you for your help :)

Dec 09 '11 at 07:31 PM OCASM
(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:

x983
x953
x198
x196

asked: Dec 07 '11 at 10:58 PM

Seen: 1089 times

Last Updated: Dec 09 '11 at 07:31 PM