Godot 4.0 provides a Project Setting called "Keep Screen On." This prevents the screensaver, or for mobile devices prevents the screen from dimming and eventually locking. But this Project Setting seems to be unchangable once launched.
How can I allow the system screensaver, but only sometimes? I wish to halt it during crucial moments, but allow it at other times (such as when the game is paused.)
An example in the wild: Mario Kart Tour prevents the screensaver and lock screen during a race, even when it receives no input. But only during a race: The moment you cross the finish line, the device will eventually time out, screensave, and lock.
Found the solution here. I was correct in that ProjectSettings.set_setting()
did not work for keep_screen_on
. Instead in Godot 4.4, you can use the function DisplayServer.screen_set_keep_on()
to change the value on the fly.
Now, for example, I can allow the device to fall asleep when the game is paused, but prevent it from sleeping when unpaused.