- Home /
How to make custom cursors work without enabling "Run in Background"?
The cursors don't work anymore after alt-tabbing out of and back into the game, unless "run in background" is enabled. I'd prefer not to enable "run in background" so the music of the game can stop playing when the game is alt-tabbed. But in this case, the cursors will no longer work when hovering over objects and the cursor will just always be the system default.
How do I make the custom cursors work without specifying "run in background"?
Answer by Bunny83 · Feb 21 at 01:15 AM
You just don't. You don't want the game to run in the background, so it can not update anything in your game, that includes software cursors as they are just another quad rendered by the game. So when you're loosing focus and "run in background" is not enabled, the game will not update or render anything.
The background music should be the least of your problems. You can disable the background music when your application looses focus manually, if that's the only thing you care about. You can manually disable the background music, but you can not manually make something happen (like updating a software cursor) when you don't let your game run in the background.
That's a good idea for a workaround, thanks for your input.
To clarify, I do not need the game to update any cursors while it's in the background. I'm talking about when the user alt-tabs to something and then goes back into the game (updated my question to fix the wording). The game is thus no longer in the "background", but the cursors are permanently broken after doing this once. This seems like a bug in Unity so I am curious how others have handled this problem. Perhaps the workaround you described is the best solution.
You can make use of OnApplicationFocus() as a place to reset state-specific, break-prone elements.
IIUC you are saying I can set run in background to false and still keep the cursor functionality after alt-tab; however, I'm not sure which part "broke" because the cursor code only lives in hover event; these hover events are still triggered but the cursor no longer changes correctly. Do you know exactly what code to put in OnApplicationFocus() to make it work?
Your answer
Follow this Question
Related Questions
How Do I Lock the Cursor to the Center of the Screen? 1 Answer
cursor misbehaves in the UI 0 Answers
How do I define the SetCursor Script? 1 Answer
change mouse cursor on mouseover 3 Answers
How Can I Lock The Cursor Position? 1 Answer