#Drawing a custom cursor in OnGUI method

1 messages · Page 1 of 1 (latest)

flint flint
#

But I draw the cursor in OnGUI method, do you say it'll have a huge impact on the performance?

private void OnGUI()
{
    // ...

    GUI.DrawTexture(rect, currCursor.cursorData.cursor);
}
granite dome
#

im not saying its huge, im saying its about 2ms per frame

flint flint
#

I am sorry, but it that a lot?

granite dome
#

just when gui is called anywhere in the project and does nothing, there is a cost to that

#

16ms is 60 fps

#

1/60 = ~16

#

2ms is 12.5% of 1 frame at 60 fps

#

those numbers vary based on the hardware ofc

flint flint
#

I see, I do more than just drawing the texture in OnGUI

#

Guess it may cause some troubles

#

perhaps you have anything to recommend me?

granite dome
#

yes the GUI system performs very poorly

#

switch to UGUI

flint flint
granite dome
#

you can do much more with UGUI than you can with GUI

#

methods/approach is fundamentally different

#

GUI loops 10 times through all the code every frame, and redraws (which means the vertex buffers are being rebuilt) every frame

#

UGUI is retained, objects are created once and then drawn, and there is very little code invocation

#

you should spend time learning UGUI, there is also UITK but i cant vouch for its readiness for actual games and its also a different approach to both

flint flint
granite dome
#

i dont, try standard unity learn

flint flint
granite dome
#

oh and with UGUI you dont need to set the actual mouse position

#

since you have Raycaster component you can modify it to "click" (which sends a raycast into the UI) from anywhere

#

so you will essentially only have the ui software cursor