Hey
I am in the optimizations phase of my game progress. I noticed that whenever I click my cursor, Cursor.setCursor uses around 1/3 of the total CPU time on that single command. I use this command whenever I click to give player feedback by changing the cursor icon for 0.2 seconds.
if(Input.GetMouseButtonDown(0) && CarryoverInfo.Instance.hasPushPower && currentCursor != CurrentCursorEnum.green) {
Cursor.SetCursor(cursorGreen, hotSpot, cursorMode);
currentCursor = CurrentCursorEnum.green;
StartCoroutine(MouseClickChange());
}
(MouseclickChange is a coroutine that sets the cursor back to default afterwards).
Now 4-8ms here and there isn’t an issue, but in my game a player can often click up to 8 times a second, so this introduces a heavy performance issue.
I tried making a object that follows the cursor position instead.
Vector3 mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
mousePos.z = -30;
transform.position = mousePos;
But compared to the previous cursor this selfmade-cursor lags slightly behind and is just less responsive, which is a no go as cursor control is the most important aspect of the game.
Is there another solution for getting click “animations” on the cursor without heavy performance dips?
Image of profiler in build:
When deep profiling in the editor I can see that it is Cursor.SetCursor_Injected( that is the culprit.
I am on 2018.3.2f1
Thanks a lot for your time.