Arcen Games

Games => The Last Federation => Topic started by: eastwind on March 10, 2015, 02:34:55 PM

Title: feature request: alt-tab should mute sound
Post by: eastwind on March 10, 2015, 02:34:55 PM
Whenever the game window loses focus (or is iconified), whether full screen or windowed mode, the game should stop all sound. If this isn't the default behavior, there should be a checkbox option to enable this behavior in settings.

The music is really nice, but the above is pretty standard behavior for most applications, since there may be other things running that also want to play sounds when they have focus.

I didn't search your bug/feature db, so +1 if this is already on your list.

I appreciate the opportunity to give feedback that has meaningful chance of being acted upon, unlike many games developed by large teams, which, counterintuitively, tend to be less responsive.
Title: Re: feature request: alt-tab should mute sound
Post by: x4000 on March 10, 2015, 03:27:12 PM
Cheers!  Unfortunately the Unity 3D engine doesn't actually let us detect when the game is minimized or otherwise doesn't have focus, which prevents us from doing this.
Title: Re: feature request: alt-tab should mute sound
Post by: eastwind on March 11, 2015, 12:02:46 AM
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationFocus.html (http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationFocus.html)

http://stackoverflow.com/questions/20528376/how-to-detect-the-state-of-an-unity3d-app-visible-or-not (http://stackoverflow.com/questions/20528376/how-to-detect-the-state-of-an-unity3d-app-visible-or-not)

Looks like you can pause the audio with AudioListener.pause.
Title: Re: feature request: alt-tab should mute sound
Post by: x4000 on March 11, 2015, 08:46:36 AM
Yep, I'm aware of those, and we have spoken to Unity about the bugs relating to this.

Quote
OnApplicationPause will be called any time the application is paused or unpaused. Note that it will only be paused if "run in background" is false in player settings, and that most code execution will stop until the app regains focus.

When we choose the "run in background" option, that causes a variety of problems, including loss of network connection if it's a multiplayer game.  That doesn't apply in this specific instance, but we try to keep things consistent.  We talked to Unity about this literally in 2011 or 2012 and still nothing. :(

The problem is that OnApplicationPause and OnApplicationFocus don't actually get called on games with the settings we use.  Keith had written a custom dll for AI War that detected loss of focus, but it was only for windows and it started having problems with windows after some various patches to windows itself.

This is the sort of thing that ought to be stupid easy, so it's one of the frustrating things about being in an engine that someone else writes. :/
Title: Re: feature request: alt-tab should mute sound
Post by: eastwind on March 13, 2015, 11:34:32 AM
Ah, ok, I apologize for not believing the first response. I don't have any experience with Unity, but other UI experience made me think it should be stupid easy as you say. My brief look at the Unity doc made me think that Unity is a "Tube Sock" UI/engine.

Title: Re: feature request: alt-tab should mute sound
Post by: x4000 on March 13, 2015, 11:54:23 AM
No problem!