-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a project setting to mute audio on focus loss #76987
base: master
Are you sure you want to change the base?
Conversation
This is disabled by default to keep expectations from the current Godot version intact. However, most games should consider enabling this option by default as it's common behavior on most PC games (while providing a way for users to disable it).
// mute_on_focus_loss_is_tweening = true; | ||
// Ref<Tween> tween = get_tree()->create_tween(); | ||
// AudioServer::get_singleton()->AudioServer::set_bus_mute(0, false); | ||
// tween->tween_method(callable_mp(this, &Window::_smooth_audio_mute_callback), -80, mute_on_focus_loss_previous_db, 0.5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to smoothly fade the transition and left a WIP as commented code. While this code works with a single window, I couldn't figure out a way to have the tweens not "fight" each other when both are triggered at the same time (due to popups creating "focus in" notifications when the main window gets a "focus out").
Checking only for window_id == DisplayServer::MAIN_WINDOW_ID
mutes audio as soon as you open a popup, which shouldn't occur.
I guess we can afford in 4.1, making it clear in the release notes, can't we? |
Another option is to enable it only in projects created with Godot 4.1 or later, using the approach described in godotengine/godot-proposals#4834. |
That makes sense. It wouldn't be the first time we tweak the default project settings to roll out a different default without affecting existing projects. |
I'm not sure this should be default, not for compatibility reasons, but because I'm not sure this is actually something that most games use. I don't recall seeing this much when playing, at least with games in windowed mode, where changing focus can be common and you typically still hear the game audio when doing so (games might sometimes auto-pause when losing focus, but still play the pause menu music). I don't have hard data on that, but I think this needs querying the community more widely than the handful of upvotes on the current proposal. Tested a few games I have installed locally: Mutes on focus loss:
Doesn't mute on focus loss:
For the few I tested, the games which do mute on focus loss don't actually mute - they pause. Any processing is stopped, and the audio isn't just silenced, but will restart where it stopped. Game logic / menu animations are paused too, and even loading levels tends to be paused. Needs more data, but it seems to me that this only does part of the work and isn't actually implementing something standard in games. |
This is disabled by default to keep expectations from the current Godot version intact.
However, most games should consider enabling this option by default as it's common behavior on most PC games (while providing a way for users to disable it).
Tested on Linux, it works as expected including when using popups (which spawn separate windows). However, pressing Alt + F9 to minimize the window (custom KDE shortcut) will not send a focus loss notification, so audio won't be muted in this case. This is an issue with DisplayServer, as minimizing by clicking the
-
button in the top-right corner sends a focus loss notification as expected.Window may not be the best location for this code, but I'm not sure what would be a more suited location.
Testing project: test_mute_on_focus_loss.zip
TODO