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
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' :)
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.
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.
This is an old question, and I agree with the answer: but there is another work around that may work for some: events are fired during MouseDrag you can catch. Read the docs on it if appropriate for you.
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' :)
– by0log1cI 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.
– WazWhat 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.
– Talimar