How to fade out sound after delay or when attached is destroyed?

Hi guys,

I did the programming tutorial with the little battery collection game and wanted to add a sound effect when the battery pickup is charging the player up. So I added a sound with 4 seconds of duration which I fade in when the charging is started and fade out when it is done (the charging takes 1.5 seconds).

I can’t get the fade out to work when calling it directly after the discharge delay, which is the 1.5 seconds needed to charge the player up. The fade in works, though. What am I doing wrong here?
Is there another, better way to fade a sound out after the battery pickup actor is destroyed?

No one got any idea? Is it possible to apply fade out in the middle of playback or does it start at the end of the playback?

I’ve tested out something fairly similar to this setup and it all seems to work correctly. Have you tried checking that the delay is definitely being set correctly? What is the problem exactly, the sound plays to the end and then stops with no fading out? Have you tried using a longer/looping sound so that you can be sure it definitely stops earlier than expected?

Hi Matthew, thanks for taking the time! Yes, the delay is definitely set correctly (see screenshot).

The problem is, the sound is played for its whole duration of 4 seconds and does not fade out at all (first I assumed the fade out is working, but when I remove it, it doesn’t sound different). I want it to fade out after the 1.5 sec delay (that’s when the battery pickup is destroyed) and stop playing after it faded out. As my sound is 4 seconds long but should end after 1.5, I’m fairly sure the fade out is not working as I intend it to. :wink:

Am I doing something conceptually wrong here, a fade out should pre-emptively end the sound playback, shouldn’t it?

Ok, so after some testing I concluded this: As soon as I put the delay in there, the fade out does not work at all (it seems like it’s not getting called, no flowing lines!). Strangely enough, when I put a break point in the fade out node, it halts there.

But when I connect the fade out directly to Play sound node, it works.

I created a new sound that started playing at Begin Play, added a delay and fade out after the delay and this one worked, too. So only in this constellation the fade out does not work after the delay, no idea why. :confused:

Hmm, glad you got it working in some fashion, i don’t know why that particular arrangement wouldn’t trigger. I think you should be able to arrange your fade in, delay and fade out in a row, i don’t think the fades wait until they’re completed. You could also keep them separated and have an event trigger the fade out instead of just waiting a set amount of time.

I finally got it to work like I want it to: I moved the Play Sound Attached node forward in the execution flow before the Sequence and the continual update of the Beam Target Point and now it works like a charm.

I also switched to using the On Destroyed Event like you suggested, I like it more this way. Thanks for your help!