Audio to match a dialog system built with Widgets and Behavior Trees

I found a tutorial on YouTube on building a Dialog System for NPCs in my Unreal Engine Project. It works great, but all it delivers is Text. I would like Audio to play along with the Text. I’ve search the internet for information on how to add Audio to a dialog system and I could not find a single resource on how to accomplish this. Audio for a dialog system seems like a common enough feature that I would expect information on how to do this would be fairly common, but here we are.

I constructed this Dialog Widget, here is the Event Graph:

This is the behavior tree:

The PlaySound about fails and gets skipped over.

This is my Speak Task:

I believe I need to add some type of Audio Variable then execute a Play Sound 2D at some point. I tried several variations but I’m confused on what the correct way to approach this is. Is there a way to play a Sound Cue via the Widget, should I be playing a Sound locally to the NPC, or are there other options? Ultimately, I think I need to get a PlaySound from the behavior tree to trigger as a variable somewhere along the interaction. Any tips, suggestions, or guidance would be appreciated.

The original tutorial: Unreal Engine 4 - Dialog System Tutorial (1/3) - YouTube

Thank you for reading all of this.

  • David

Hey David, I don’t use Behavior Trees so my way would all be in the Widget :
First you create an Array of SoundWaves variable, and populate it with your sound files.
(I’d avoid using SoundCues because they complicate things and are about to turn legacy for many good reasons)
Make sure this voice Array is parallel to your “Replies” text Array, so that every text line has its matching voice line on the same Index number.
Then, on the event when you display the text, get its Index Integer and call Play Sound 2D on the sound with that Index.
This is the simple way, and it will play a non-spatialized sound, meaning without the sense of being positioned in the world.
It may sound like “the voice in my head” and be suitable for the player’s reply, so if you want it to come from the AI Character -
Replace that Play node with Spawn Sound at Location or Spawn Sound Attached, wire the Target Sound pin, wire your NPC to the Location or Attachment pin,
Lastly, in the Content Browser create a Sound Attenuation Setting and select it in the appropriate window on the Spawn node, see my screenshot for reference.
Hope that helps :slight_smile:

Thanks for the reply, ebarkani. I ended up doing it through the widget but with a variable set via the dialog tree.

I added a Sound Cue variable to my Behavior Tree Custom Task.

I told the widget to play the Sound Cue which was assigned in the Behavior Tree.

Eventually I would like to sync audio with character animations. I know I can link audio with an animation blueprint, but I’m unsure if I can add an animation blueprint to an array (a superior method I have not implemented yet) and call it from the Widget as I have done with the audio file above. Much more for me to explore!

Glad to hear you got it going. Your screenshot doesn’t show the logic you used to match a sound to its associated text, but as long as it works for you…
Syncing audio and character animation is definitely a big thing, which I’m currently exploring too (in more of a musical context rather than dialog).
I’d suggest looking into Animation Montages - sequences you create and call, switch between, blend and layer up etc, within a character’s Animation Blueprint.
Best of luck !