Before I get a lot of “Read the forums” and “code a gui texture” replies, let me clarify: Is there a way to change the hardware mouse, i.e. the one that renders at 60fps, independent of the program?
I know you can alter the Windows registry to change the hardware mouse, but I’m not sure how to do it on a Mac. I’m currently rendering a GUITexture at mousePosition, but that way is too slow. Unity’s GUI simply can’t keep up with the pace the mouse moves at, even at 40fps.
I know this can be done, because games such as World of Warcraft (which is cross-platform), when played in windowed mode, will change the cursor until the focus leaves the game window.
This is something that really needs to be accomplish-able.
I need to change the hardware mouse to my custom, not show the default one.
Alternatively, is there a way to make the standard Unity workaround any faster? I have this:
void Update ()
{
if (!lockCursor)
{
int nextX = (int)Mathf.Round( Input.GetAxis("Mouse X") * cursorRateX * scrollRate);
if (Statics.mousePosition.x+nextX < Statics.screenWidth Statics.mousePosition.x+nextX > 0)
Statics.mousePosition.x += nextX;
int nextY = (int)Mathf.Round( Input.GetAxis("Mouse Y") * cursorRateY * scrollRate * -1 ); // Inverted because Unity uses a
// bottom-left-based screenpos coord
// system, and we're emulating that
if (Statics.mousePosition.y-nextY < Statics.screenHeight Statics.mousePosition.y-nextY > 0)
Statics.mousePosition.y -= nextY;
cursorRect = new Rect(Statics.mousePosition.x, Statics.screenHeight - Statics.mousePosition.y, cursorWidth, cursorWidth);
}
}
and
void OnGUI()
{
if (showCursor)
{
GUI.DrawTexture(cursorRect, cursorIcon);
}
}
Where Statics.mousePosition is a Vector2 that stores my custom mouse position (so I can do things such as manually move the psuedo-cursor, for instance), and Statics.screenHeight is the equivalent of Screen.height.
I know this would not work with a hardware mouse, but either way, I need a fast cursor that isn’t the system default one.
Just a thought - Do you mean ‘faster’ as in the mouse seems to lag when you move it because the mouse is only being updated once per frame? What about if you used FixedUpdate instead? Can you set the frequency of FixedUpdate?
I do mean faster that way, yes - because the cursor does lag behind the mouse - but FixedUpdate is only called once per physics step, so it’s usually a lot slower than Update.
No, you can’t set the FixedUpdate interval (which you do via Time.fixedDeltaTime), because that would mess up your physics.
Hmm. So you couldn’t start a timer to execute at 60fps to handle mouse?
Just had a look at another post and saw eric5h5 mention OnGUI, which seems to run faster than 'Update? Perhaps this is the place to put the mouse update code?
Unfortunately, if your code is running at <60fps, you can’t write something that will force it to execute faster
OnGUI can run faster than Update, but it doesn’t always. Through testing I found that it runs just as slow in my example. What I really need to do is just alter the hardware cursor.
You could force it to run faster if it was threaded - your physics/rendering etc in their own threads running at <60fps, your mouse code running in a separate thread at >60fps.
But going back to your original questions - sorry, I don’t know how to change the hardware mouse cursor
The only way to use a coroutine is to pass it a yield instruction, and the shortest one is yield return null;
Unfortunately, that’s what the Update loop does, and you can never go faster than it.[/code]
There is a massive missconception, cause coroutines have nothing to do with threads at all. there is no unity mechanism that runs in an own thread which would be programmable to you and you can’t use threading to access unity either or it will crash.
The System.Windows.Input.Mouse.SetCursor() method would do what I want, but the Windows namespace isn’t included in the System namespace that comes with Unity.
Still no solution for changing the hardware mouse, but did come across a timer-like call that could run faster than update so that you can update the mouse cursor position more frequently (possibly) - it may help!
I think that the only instance where a Unity function can run faster than an Update is if the looped function has fewer lines to chew through than Update. Since my Update loop only contains logic for updating mouse position, I don’t think I’m going to squeeze any more performance out.
sorry i just noticed that while reading through your posts
as far as i know Update runs every physics step and FixedUpdate runs several times and is in fact much faster than Update I use FixedUpdate for things like targeting reticules that follow the mouse cursor as Uptade is too slow the clue to their diference is in the names realy
update = updates every physics step or few times a physics step
FixedUpdate = updates regardless of physics step at a fixed state.
maybe look it up i dunno.
i could be wrong but my mouse targeting system dont lie lol
If I understand what you are saying correctly, then you have it backwards. FixedUpdate runs once every physics step which is a fixed time. You can set the physics step in the Time manager. This way when the framerate drops, the physics is still calculated properly. Update is called every frame so depending on the frame rate could be more or less than the Fixed update.