x


Capturing Mouse Position w/o Polling Every Update?

Hey everyone,

For my GUI, I'd like to use keep track of the mouse position while avoiding simply polling for the position every Update(). Ideally, I'd like to leverage the "mouseMove" event since then I can unnecessary code execution when the mouse position hasn't changed, but the mouseMove Event isn't fired in game (only the editor, see http://unity3d.com/support/documentation/ScriptReference/EventType.MouseMove.html).

Does anyone have a good workaround for this problem? Is there a efficient, standard way to capture mouse position that I'm just overlooking?

Thanks,

Nate

more ▼

asked Sep 01 '11 at 10:32 PM

Nathan7 gravatar image

Nathan7
1 2 2 3

I can't help but wonder if this isn't a little overkill? A simple Input.mousePosition poll once a frame probably isn't noticeable IMHO (is it?). I'm interested in any performance improvement this thread might bring but my two cents is 'just get it if you need it' :)

Sep 01 '11 at 10:40 PM by0log1c

I agree with BY0LOG1C. If your problem is a high-cost operation you need to do each move, then compare position to last frame and avoid the operation when zero change, but just the call to get the mousePosition is immaterial compared to everything else you need to do every frame.

Sep 01 '11 at 11:27 PM Waz

What Warwick said needs to be made the answer. This is such an insignificant use of resources and you have far bigger things to worry about.

Sep 01 '11 at 11:33 PM Talimar
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Since your problem is a high-cost operation which you need to do each move, solve this by comparing the mousePosition to what it was in the previous frame and avoid the operation when the change is zero. The actual cost of reading mousePosition is immaterial.

more ▼

answered Sep 02 '11 at 12:41 AM

Waz gravatar image

Waz
6.4k 22 33 71

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

x3688
x984
x64
x12

asked: Sep 01 '11 at 10:32 PM

Seen: 1021 times

Last Updated: Sep 02 '11 at 12:41 AM