|
Post by Illusion Walk on Nov 3, 2020 17:50:49 GMT
Hi,
I have realized that 2D sounds are spatialized (at least a bit) even if the AudioSource.spatialBlend is set to zero. Maybe it is a problem that came only with Unity 2019 or occurs in VR (using Oculus). But only when disabling AudioSource.spatialize it will be played as a real 2D sound.
Unfortunately the MasterAudio SoundGroupVariation will set the spatialize field only on initialization.
To play the SoundGroup as 2D or 3D sound depending on the current spatialBlend value I have slightly changed the SetSpatialBlend method of SoundGroupVariation.cs at line 289:
public void SetSpatialBlend() { var blend = ParentGroup.SpatialBlendForGroup; if (blend != MasterAudioGroup.UseCurveSpatialBlend) { VarAudio.spatialize = blend != 0; // Added: It is important when playing 2D sounds to disable spatialize even if spatialBlend is 0 VarAudio.spatialBlend = blend; }
var aBus = ParentGroup.BusForGroup; if (aBus != null && MasterAudio.Instance.mixerSpatialBlendType != MasterAudio.AllMixerSpatialBlendType.ForceAllTo2D && aBus.forceTo2D) { VarAudio.spatialize = false; // Added: It is important when playing 2D sounds to disable spatialize even if spatialBlend is 0 VarAudio.spatialBlend = 0; } }
Is this behavior intended? Maybe it could be fixed in further versions?
Thanks!
|
|
|
Post by DarkTonic Dev on Nov 4, 2020 4:02:34 GMT
To be clear, I was never setting that field (spatialize) before right? If so, I can incorporate your changes. Please let me know.
|
|
|
Post by Illusion Walk on Nov 4, 2020 13:07:36 GMT
Yes, the SetSpatialBlend method just set the spatialBlend value before. I have added the two commented lines to set the spatialize bool as well. That would be great.
|
|
|
Post by DarkTonic Dev on Nov 4, 2020 16:40:42 GMT
I have fixed this and in Playlist Controller as well for the next update.
|
|
|
Post by Illusion Walk on Nov 4, 2020 17:16:11 GMT
Thank you!
|
|
|
Post by DarkTonic Dev on Nov 4, 2020 17:28:47 GMT
No problem.
|
|
|
Post by Illusion Walk on Nov 16, 2020 17:30:01 GMT
Thank you for solving and releasing the fixes so quickly.
Unfortunately the bug isn't fully solved for my use case (2020.3.5). I would like to play the variant with both modes (2D and 3D) but the spatialize bool still won't be updated. That is why I'm setting the bool in the SetSpatialBlend method in SoundGroupVariation.cs at line 289 as written in my first post (see the commented two lines).
Or is there any other reason not to set the bool at this point?
|
|
|
Post by DarkTonic Dev on Nov 16, 2020 18:57:12 GMT
Each Sound Group has a fixed Spatial Blend, so you can't play it in both 2D and 3D anyway. You choose 2D / 3D or somewhere in between during edit time. SpatialBlend and Spatialize properties will only be set once, during Start.
The code to set .spatialize now lives in SpatializerHelper.cs, this method:
private static void SetSpatializerToggleOnSource(AudioSource source, bool enabled)
Now I see that the logic wasn't right. So change that method to this and let me know:
private static void SetSpatializerToggleOnSource(AudioSource source, bool enabled) { #if UNITY_2017_2_OR_NEWER if (enabled) { enabled = source.spatialBlend != 0; }
source.spatialize = enabled; #else // no spatializer! #endif }
You can check whether it's getting called, but it should be. That method actually is called after SetSpatialBlend, but it shouldn't matter.
|
|
|
Post by Illusion Walk on Nov 17, 2020 16:31:28 GMT
Thank you. I've tried your changes.
It works for me if I add TurnOnSpatializerIfEnabled() to SoundGroupVariation.cs at line 418 like this:
// in case it was changed at runtime. SetSpatialBlend(); SpatializerHelper.TurnOnSpatializerIfEnabled(VarAudio); // <== Added line: Update spatializer if was change
|
|
|
Post by DarkTonic Dev on Nov 17, 2020 16:45:13 GMT
Ok, I've added the method call there as well.
Thanks.
|
|
|
Post by Illusion Walk on Nov 17, 2020 18:15:03 GMT
Cool. Thank you!
|
|
|
Post by DarkTonic Dev on Nov 17, 2020 19:52:58 GMT
No problem.
|
|