Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by OCASM · Dec 07, 2011 at 10:58 PM · inputmouselagcursor

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OCASM · Dec 08, 2011 at 08:49 AM 0
Share

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.

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OCASM · Dec 09, 2011 at 07:31 PM 0
Share

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 :)

avatar image
0

Answer by unimechanic · Oct 10, 2013 at 06:09 PM

Try disabling vertical synchronization to update the frames faster:

QualitySettings.vSyncCount = 0;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges