Cursor.SetCursor slow on Windows builds

Our game has a system where the cursor color is changed when it’s over something clickable and in some some special cases it actually sets the cursor twice per frame (first to plain, then to highlighted). In the editor this happens instantaneously, but I noticed that in Windows builds (Windows 7) it actually took 33ms per frame.

Did some digging, noticed that Cursor.SetCursor takes a long time in the builds whenever it actually changes the texture. Changing once was about ~15 ms, twice ~33 ms and so on. 3 calls in one frame takes 50 ms. Seemed like it’s waiting for screen refresh, so I added a Thread.Sleep(10); just before and profiled again and now Cursor.SetCursor took about 10 ms which seems to confirm it.

I reported a bug too, Case 721323.

1 Like

Well, I ended up revising our scripts so that the cursor is only changed once per frame in a LateUpdate. This could likely be a DirectX-thingy that can’t be affected on Unity’s side, in which case it should probably be mentioned in the documents.