Is there a callback when a sound cue has finished playing?

Hi there,

I want to get a callback of some kind when my sound has finished playing. Is there a way I can do that?
I have a sound cue containing a part of dialogue. I want to know when it is finished so I can play the next part of the conversation.

Thanks,

  • Rich

I was looking into that issue as I had that problem with UMG animations. I solved it with the use of delay nodes and some other workarounds, but I donā€™t exactly like it either :(.

I see. Thanks for the reply. Yes, I could use a delay node.
The issue for me is, I donā€™t know how long the dialogue is going to be. Is there a way to find out the duration of a sound?

UAudioComponent has an OnAudioFinished delegate that you can hook an event to.

This is the way to do it - the trouble is that it isnā€™t easy to use from within Blueprint. I used a custom component to manage audio components, bind the delegate and trigger a blueprint event within that class (Iā€™d share the code, but itā€™s very specific to the project Iā€™m working on, so not really that useful to anyone else).

Handling it through audio components isnā€™t a bad way of doing it though. Iā€™d avoid the ā€˜PlaySoundā€™ nodes that are available by default if youā€™re going to want a callback when the audio is complete.

1 Like

Why is this not easy to use? Why have the bp wich plays the sound in the same bp you can handle the OnEndPlay (or whatever you want to call it)

Thahts one way to deal asynchronous stuff

I did say handling it through audio components isnā€™t a bad way of doing it. The issue occurs when youā€™re doing it from somewhere like the Level Blueprint, where youā€™re normally expected to use the static gameplay functions rather than components. Whilst you can add an audio component to the level blueprint, or spawn them as and when you need, itā€™s not ideal - hence why I created a class to manage that for me (because this project contains a lot of level specific dialogue).

ah i see well yes in that case a maybe playback actor would make sense. you would still be able to rerebind the finished event to your maybe level blueprint or whatever :smiley:

Would you be willing to share some of how you did that? Iā€™m actually trying to do the same thing myself, because I donā€™t want to have to add an actor/scene component to a level to be able to properly control my audio the way I want to, and Iā€™m having trouble figuring this stuff out on my own.

Iā€™m a programmer first and artist a distant second, and have 0 music or audio skills to save my life. lol

My game has BG music that needs to have an intro, a looping chorus, and an outro (where the middle part of the audio is looping until some goal is accomplished, for instance defeating the level boss, at which point I turn off looping). Iā€™ve got a sound cue set up for this purpose, and I figured out thereā€™s a node for setting looping settings (number of times to loop, or looping enabled or disabled). And Iā€™ve got some code set up (currently in an actor because I couldnā€™t figure out how to add an audio component to a level bp) which allows me to sequence through the cue from 0-3 (0 is gonna be no audio, effectively disabled, and when I start my level, Iā€™ll begin the process of incrementing it, up to 1 for the intro, 2 for the looping chorus, and 3 for the outro. 1 and 3 are not looping by default, but 2 is looping by default, as I intend to turn off looping on 2 when an event/function is called. when 1 ends, I call the increment function, when 2 ends after looping is disabled, again increments it to 3).

My trouble currently is I donā€™t know how best I should set up the audio component in the level (levels arenā€™t set up to follow parent/child relationships, but I made a ā€œlevel parentā€ that I duplicate for each level I make, and simply change the wave files for each level, but the logic should function identically), and would ideally LIKE to attach it directly to the level like you said, not add it as an actor. In addition to that, I am not sure how to make index 2ā€™s looping audio no longer loop upon a set event happening. Iā€™ve got a node for that in the Cue but donā€™t know how to basically make that happen on call.

Edit: Wait, I see now you were saying NOT to add it to the level as a component. Makes sense then why itā€™s not an option in UE5. Given that it seems impossible to do without having an actual actor spawned somewhere in the level (which means I have to remember to do that every time I make a new level), it might be best if I just add one to my level parent and then when I duplicate that, rather than delete everything in the viewport and start fresh, I just adjust things to change how each level looks so that I leave the spawned actors where they are.

Aside from that, do you know how I would be able to trigger the change of looping like I said above?