How to add sound effects to UI?

Hi, as to my understanding, it needs audio trigger and audio proxy component to play sound effects. However, UI elements are all in UI editor, is there anyway to play sound effects like “button click” when the UI button is clicked? Thanks!

Hi @SIjier,

You can play sounds by listening for the UI events in Lua, Script Canvas or C++ and playing the sound effects from there.

At some point we may support tighter integration of audio into the UI system. Any suggestions on how you would ideally like that to work would be welcome.

Rob

Thank you so much!

Thanks for the response @RobP!

Just so I understand correctly, Script Canvas works differently in the UI Editor vs. the ‘Main’ Editor.

In the UI Editor I can only create an out event that requires code in order to hear it.

In the ‘Main’ Editor, I can create an event in Script Editor that I can hear in engine without code.

(reason I ask is so I can create & test UI audio events without needing an engineer :slight_smile: )

Hi @crogue,

There are few different way to listen for events. The easiest from Lua is to use the UiButtonNotificationBus, documented here:
https://docs.aws.amazon.com/lumberyard/latest/userguide/lua-scripting-ces-api-ui-uibuttoncomponent.html

You can do the same from Script Canvas. You can add a script canvas component to the button element in the UI Editor. Then in the script canvas add the UI Button > On Button Click node. Leave it set to Source = self. You should then get the out event when the button is clicked.

If the script canvas is on a different element you can drag from the button element in the UI Editor’s hierarchy pan onto the Source field in the Script Canvas editor.

I hope that helps,

Rob

Hi @crogue,

Currently the way to play audio based on a UI related action (such as a button click) is to use the UI notification buses to listen for such events. You can do this from Lua or Script Canvas. For example, you can add an “On Button Click” node to a Script Canvas script, and hook up its Out parameter to another node that plays a sound. In a Lua script, you would connect to the UiButtonNotificationBus and provide a function called OnButtonClick that would contain code to play a sound.

Could you explain what you mean by being able to create an event in Script Editor that you can hear in the engine? Do you mean that you can use one Audio Trigger node in Script Canvas to play a sound?

Hi @RobP - sorry to reopen this thread, but can you please clarify what you mean by “… listen to the UI events in Script Canvas”? I’ve created a ‘UI Button’ event in Script Canvas, but I can’t add it within the UI Editor (‘Variables’ is grayed out)… guessing this is because I can’t add ‘Audio Trigger’ and ‘Audio Proxy’ within the UI Editor (as per @slijier above)… thx

Hi @Michelle,

Thanks for helping out… I’ve attached screenshots of where I’m at:

Screen 1: Script Canvas script for a Button Click audio event (this structure works perfectly for Audio Area Environments)

Screen 2: UI Editor properties for the button I’m trying to create a sound for (linked to the above script). I’ve tested ‘Play_ui_click_1’ through other implementations and it plays fine.

Sadly, when I play the game, no sound when clicking the aforementioned button…

… so the current working hypothesis is that when I create an Audio Area Environment, Lumberyard requires you to add Audio Trigger, Audio Proxy & Trigger Area, which are not options within the UI Editor. So no sound.

Appreciate any guidance you can provide.

Hi,

The “Execute Trigger” node is expecting Source to be assigned to an entity that has the Audio Trigger & Audio Proxy components on it. Unfortunately these components are not available to be added to UI entities, and you cannot assign a world entity to Source since the Script Canvas is attached to a UI entity. Here are a few thoughts:

  1. Try making the Audio components available to UI entities. This would require C++ work.

  2. Try sending a message from one Script Canvas on a UI entity to another Script Canvas on a world entity that would play the sound. I’m not sure whether Script Canvas supports custom events though.

  3. Create a game specific layer in C++ that would allow playing audio globally without the need to associate Audio Triggers to entities.

understood - thanks @Michelle

I do not see nodes in script canvas lumberyard 1.18 for Audios/Sounds , please add nodes for Audios/Sounds in script canvas (without use lua & c++)

I do not see nodes in script canvas lumberyard 1.18 for Audios/Sounds , please add nodes for Audios/Sounds in script canvas (without use lua & c++)

I do not see nodes in script canvas lumberyard 1.18 for Audios/Sounds , please add nodes for Audios/Sounds in script canvas (without use lua & c++)