- Home /
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.
Answer by rabbitfang · Dec 07, 2011 at 11:59 PM
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.
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.
Answer by ks13 · Dec 08, 2011 at 09:38 AM
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.
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 :)
Answer by unimechanic · Oct 10, 2013 at 06:09 PM
Try disabling vertical synchronization to update the frames faster:
QualitySettings.vSyncCount = 0;
Your answer
Follow this Question
Related Questions
Issues with mouse input when locking the cursor 0 Answers
Disable mouse input and cursor in game 2 Answers
Mouse input lag causes line rendering jitter 1 Answer
mouse Input Instantiate 0 Answers
Input System Can't Catch Event on Update 0 Answers