0

In Unity you can prevent the screensaver kicking in / inactivity timer from shutting the computer down by using the Screen.sleepTimeout setting:

Screen.sleepTimeout  = SleepTimeout.NeverSleep;

However this only seems to work if the application is the active Window. If another Window is in the foreground, and my Unity application is in the background (but still visible), then the screensaver activates after the timeout period, even when this setting is set.

Is there another way to do this that will keep everything alive as long as the application is running, even when it is in the background?

[Behaviour described is seen on Windows - it may or may not be different on other platforms, but I'm looking for a cross-platform solution if such a thing exists, or just a Windows one if this is a peculiarity of Windows!]

Dogtanian
  • 1
  • 1
  • Is you application set to run in background? That might make a difference here. For the PC build, select Edit > Project Settings, and then enable the Run In Background checkbox. – hijinxbassist Apr 19 '23 at 20:52
  • Yes, that setting is already set. The application runs in the background, but it just doesn't stop the screensaver from kicking in as it does when it runs in the foreground. – Dogtanian Apr 19 '23 at 21:14
  • From [docs](https://docs.unity3d.com/ScriptReference/Screen-sleepTimeout.html), `Most useful for handheld devices, allowing OS to preserve battery life in most efficient ways. Does nothing on non-handheld devices.` – hijinxbassist Apr 19 '23 at 22:06
  • That's exactly the substance of my question - using Screen.sleepTimeout isn't the right way to do this...so what is? – Dogtanian Apr 20 '23 at 06:24
  • I believe you need to implement platform specific implementations. [No Sleep Windows](https://stackoverflow.com/questions/49045701/prevent-screen-from-sleeping-with-c-sharp) – hijinxbassist Apr 20 '23 at 16:42

0 Answers0