Conditional Wav switching in UE4
You know how player jumping works in UE4, with a start-to-jump animation that plays once, then an in-the-air loop animation, then a landing animation that plays once? I was wondering how to do the same thing with audio, when you don't know how long the middle part may be.
My case is to do with vehicle fueling. When you are fueling a vehicle, a sound plays at the onset of fueling, once, and after it, there's a loop during the fuel progress, and either when you are full or when you let go the fuel input, there's a stop sound. The exact time when each of these should play varies, so you need to drive it from a condition.
Switch by integer and by bool parameter are similar, though you can have more than two sounds to flip between if you switch by integer.
An alternative way to do this, is that you could have a parameter called pump and wavs like:
0, start
1, loop
2, end
Bear in mind that the Parameter Unset needs an input Wav, or it will play nothing.
It would make a little more sense if this was just a parameter keyword entry (let's just say it is fine once you know to connect a Wav to it).
In blueprints, the Set Integer Parameter > In Name controls the soundcue's Switch > Int Paramater Name.
The Set Boolean Parameter in blueprints does the equivalent for bool nodes in the soundcue.
It's best to organise your spawned sounds with variables, as shown below. Don't forget you may need to Convert to Validated Get in some situations or you may get Null reference errors.
In the spawn options, the Auto Destroy tickbox is on by default. When sounds are stopped or complete, they are cleared away. To make the soundcue persistent, turn this off, then you can restart or replay sounds (presumably it doesn't matter for sounds set to loop).