How do FadeIn/FadeOut work internally? Can fades be arrested/reversed after being triggered?

We’ve got a background music system that juggles big sound cues (each containing multiple layers of looping soundwaves) when moving between areas of the game. It all works nicely: rather than fading out a BGM cue when you leave an area, we simply override the currently-playing cue with the new one. All BGM cues are loaded into an array of components at game start, so:

player overlaps new area
-> trigger volume overlap event contains area name
-> all components that don’t match that name get a FadeOut
-> the one that does match gets a FadeIn

That’s great, and means that the player can move from Area1 to Area2 and get a smooth crossfade between BGM1 and BGM2. But if they cross to Area2 and immediately walk back into Area1, BGM1 has begun its FadeOut and will quickly stop (3s fade), leaving Area1 with no music playing (because FadeOut stops playback at 0.0 vol).

To prevent this, I currently have a workaround with a delay (0.1s longer than the cues’ FadeIn/FadeOut times, so the FadeOut is always allowed to run to 0.0 before a FadeIn is called) which results in a slight gap between BGM when changing areas, rather than a nice crossfade blend.

So it would be awesome if I could arrest/pause an in-progress FadeOut (e.g. BGM1’s FadeOut that was triggered when player entered Area2) when the player suddenly reverts to Area1 - and simply fade it up from its current fade level back up to 1.0. The documentation suggests that the Fade functions change the volume multiplier, but when I monitor the volume multiplier during Fades, they stay the same - seems like they use an internal multiplier or one that isn’t readily available to me.

Can anyone shed light on whether that multiplier is accessible in BPs, or where I might tell our C++ coder to go looking for it, so we can come up with a workaround for this? Or do I need to resign myself to a complicated spiderweb of Timeline logic?

TL;DR VERSION: how can I get the current volume multiplier of an in-progress FadeOut? :slight_smile:

Cheers!

Rather than using audio component fade in/out directly, you can just do the fade yourself in BP and set a volume value with a shorter fade duration in a BP timeline callback. You could also just hook it up to a UE4 curve asset and do your own sweeping through the curve to control the fade. You’d only then need to use an audio component fade time value equal to the the time-delta between updating your manually controlled fade curve.

Something as simple as the following should work –

In the timeline, you can use a UE4 Curve asset or just draw the fade curve.

Optionally doing a linear-to-dB conversion might result in a nicer fade. The Volume Multiplier value on audio components is a linear volume value currently so it’ll sound better if you either do a non-linear curve or do a linear curve (in dB) and convert to linear volume value before setting it on the audio component. dB-based fades always sound better than linear fades (since volume perception is non-linear, it’ll sound linear if it’s exponential).

So, doing that would look something like this:

Where the timeline curve is just a simple line going from (0.0, 0.0), to (1.0, 1.0).

fadecurve.png

Thanks very much! And for the example of how to map a linear curve to exp dB - very handy. I did replace FadeIn/FadeOut with a Timeline system last night after posting, but in a much clunkier way than this.

At one point I found myself trying to programmatically instantiate an array of Timeline components at runtime, one per BGM cue, so that I could handle them independently…but a) that doesn’t seem possible (unless I manually create a pool of them in the BP and hope there’ll always be more Timeline components than there are BGM cues) and b) I may not be understanding Timelines properly in terms of their instantiation/scope/OOP-ness…

If I have [n=arbitrary number of] BGM audio components and just one Timeline, could I use that Timeline to handle fading (in either direction) between any two given BGM audio components, rather than needing each component to have its own Timeline? Perhaps by always ensuring the fading-out cue is getting an inverted volume multiplier to the fading-in cue’s multiplier so that it works like a DJ mixer-style crossfader? (Gonna give that a shot anyway)

Cheers!