A Lesson in Unreal & Audio - Tim Kim
Hi, everyone! With the release of our second update here, I'd like to share with you all everything that I've learned during my journey as a developer in Unreal - but I don't think a single blog post is going to be able to cover all that (nor do I think you all would find it all that interesting.) Instead, I'm going to share with you an interesting "problem" I found.
Preface
At a certain point during my tasks, I found myself needing to dive into the audio components of our game. I'm currently in charge of our game's UI design and functionality and one of those areas happens to be your typical "Options" menu. In an Options Menu, you'll find quite a few parameters you can set as the end user of any game, but a crucial and staple point of customization is going to be volume adjustment.
In the picture above, you can see that we currently only have it set to a single slider, which currently serves as our Master Volume Slider. Set up for the game's audio took a bit of research, but was not an overtly difficult task to accomplish. The main idea is that you need to create different classes for each desired channel you want for your game and ensure that your Master Sound Class serves as the parent for all subsequent classes, like depicted below:
And then it's a matter of ensuring that your desired SoundWave object has the appropriate class specified in its Sound->Class field
Takes a bit of work, but as I've explained - not too overtly complicated, right? I can hear you asking, "So, then what's the problem?"
Problem
After initial setup and confirming that the volume adjusts accordingly to the slider in real time, I decided to run one final test: if I lower the slider volume all the way down to it's lowest value, I should be able to cancel out all sounds. After which, I should be able to bring the sounds back if I so desire. Well, at this step of my setup, I found that this was not the case. I could reduce the volume down to zero, but for some reason trying to bring the sound back from zero would not increase the sound volume whatsoever. Why?
Well, it took a bit of experimenting and digging around, but I found the solution here...
Solution
Through digging around online, I was able to figure out the algorithm necessary to create the functionality of the slider itself, as demonstrated with my work below:
Nothing too fancy. Mostly utilizing AudioDevice to begin overriding specific attributes of a Sound Mix Class, which then we apply via the AudioDevice's PushSoundMixModifier. But when I began to realize that sliding the slider's value all the way down to zero and not being able to bring the sound back made my dig specifically into AudioDevice's SetSoundMixClassOverride function, and this is what I found:
See how that function from the FAudioDevice class attempts to find the adjusted values from my slider function in a map that Unreal stores internally? Also notice that if that ClassOverride does not exist, then it creates a new class and adds this to existing map? Lastly, notice that if that specific ClassOverride already exists, then it overrides the previous entry's values? This is great and all, but what does any of this have to do with our problem? Here's the problem:
When the Volume float input that you pass into this function is 0, anything multiplied by zero will always be zero. No exception.
With this revelation, I then changed the Min Value of my slider from zero to 0.01 and found that not only can I simulate the absence of sound with this new Min Value, but I can also now successfully bring audio back from it's "near zero" state.
And thus, after some research and setup, I was able to successfully create our game's functioning Master Volume Slider. From here, it's a simple matter of setting up the sliders and functionality for the other channels and making sure I change the default Min Value of each slider!
No Rest For the Wicked
Status | In development |
Author | ClashWorks |
Genre | Strategy |
Tags | First-Person, Horror, Real time strategy |
More posts
- Persistent Data - Jaren Urey1 day ago
- Small things can make or break your progress - by Mason Miller2 days ago
- Collisions can be Tricky - Mason Miller9 days ago
- Lesson in Perforce-Unreal Relations - by Tim Kim9 days ago
- "From scratch" -Jaren Urey 9/11/202510 days ago
Leave a comment
Log in with itch.io to leave a comment.