How to add sound effects to UI?

0

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!

已提問 6 年前檢視次數 221 次
12 個答案
0
已接受的答案

Hi @REDACTEDUSER

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

已回答 6 年前
profile picture
專家
已審閱 1 個月前
0

Thank you so much!

已回答 6 年前
0

Thanks for the response @REDACTEDUSER

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 :) )

已回答 5 年前
0

Hi @REDACTEDUSER

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

已回答 5 年前
0

Hi @REDACTEDUSER

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?

已回答 5 年前
0

Hi @REDACTEDUSER

已回答 5 年前
0

Hi @REDACTEDUSER

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.

REMOVEDUPLOAD

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.

已回答 5 年前
0

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.

已回答 5 年前
0

understood - thanks @REDACTEDUSER

已回答 5 年前
0

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++)

已回答 5 年前
0

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++)

已回答 5 年前
0

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++)

已回答 5 年前

此貼文已關閉:已停用新增新答案、評論和投票功能。