# \[CLOSED\] How could I return from my \*function\* when my sound has finished playing?

**URL:** <https://forums.unrealengine.com/t/closed-how-could-i-return-from-my-function-when-my-sound-has-finished-playing/1252611>\
**Category:** Blueprint\
**Tags:** unreal-engine, functions, Blueprint\
**Created:** [August 6, 2023, 2:52pm UTC](https://forums.unrealengine.com/t/closed-how-could-i-return-from-my-function-when-my-sound-has-finished-playing/1252611 "2023-08-06T14:52:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marci1209](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Marci1209](https://forums.unrealengine.com/u/Marci1209)\
**Post date:** [August 6, 2023, 2:52pm UTC](https://forums.unrealengine.com/t/closed-how-could-i-return-from-my-function-when-my-sound-has-finished-playing/1252611/1 "2023-08-06T14:52:15Z")

</div>

Hello. I’m making a dialogue system for my game, and I wanted to play a sound and then return only when the sound finished playing. I tried replicating what another user answered in a [similar post](https://forums.unrealengine.com/t/how-to-bind-an-event-to-audio-finished/474085/6), but I couldn’t create a custom event in my function (I read that I couldn’t). How could I adapt that code, or make it work for my function?

BTW, this is my blueprint for the function:

 ![CleanShot 2023-08-06 at 09.34.38@2x](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/f/7df8469671dd6bc87d0d7c4998c81afb99203a1e.png)

And this is where I got stuck:

 ![CleanShot 2023-08-06 at 09.35.20@2x](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/7/5/075782e9a778c66eafbc93d324f1a2a10eae01d9.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 6, 2023, 3:47pm UTC](https://forums.unrealengine.com/t/closed-how-could-i-return-from-my-function-when-my-sound-has-finished-playing/1252611/2 "2023-08-06T15:47:37Z")

</div>

You can’t put time dependent things inside functions, as you’ve discovered 😉

But you can parameterize custom events. And then really, what is the different between that and a function?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/3/62397d6f452d09a638accb6b666ab143119a1b24.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/c/33cca6326f3056cd1d462bb7d377125b319aab32.png)

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [August 6, 2023, 5:03pm UTC](https://forums.unrealengine.com/t/closed-how-could-i-return-from-my-function-when-my-sound-has-finished-playing/1252611/4 "2023-08-06T17:03:24Z")

</div>

In general, you should structure your dialog system as a state machine with current state, and transition events.  
The transition events can of course be implemented in functions.

Somewhat unpopular but correct observation: You should in general never use “Delay.” It feels convenient for many things, but it frequently ends up causing bugs that are hard to debug as your game logic scales up.
