Skip to main content

Flexi Sound System

Overview

Flexi Sound System uses a universal Audio Engine called Flexi Audio Engine that can play mp3, wav, ogg and other common audio formats. The 2D, 3D and action sound effects can be added by using Flexi Audio Engine in the Editor.

Sound System Configuration

Click Config -> Project Settings and select General Project Settings in the pop-up Project Settings window. Then select FLEXI as Sound System in Sound Settings (Restart needed after modification).

image-20221019171003344

After configuring Sound System, click 2022-09-23_112337 button next to Settings Path in Sound Settings and select the saving path for sound resources in the pop-up File Browser.

image-20221019171014892

2022-09-23_111810

Adding UI Sound Effects

There are three types of UI sound effects: Sound Effects When Mouse In, Sound Effects When Mouse Out, and Sound Effects On Click.

Opening the UI Editor

Right-click on the blank space of the Resource Preview window and select UI File, double-click the UI file to open the UI Editor.

2022-09-23_114209

Sound Effects When Mouse In

The bound sound effect will be played when the mouse is moved into the range of the control.

Select the control that needs to be modified in the UI Editor, then select InSound in the Properties list of the selected control. In the pop-up Select Event window, select a sound file and click OK (or double-click the sound file) to set the property for the control.

Now move the mouse into the control and the sound will be triggered.

2022-09-23_132358

Sound Effects When Mouse Out

The bound sound effect will be played when the mouse is placed over the control and then moved out of the control's range.

Modify the OutSound property of the control to add the corresponding sound file to the control in the same way as the InSound property.

2022-09-23_133322

Sound Effects On Click

The bound sound effect will be played when clicking on this control.

Modify the ClickSound property of the control to add the corresponding sound file to the control in the same way as the InSound property.

2022-09-23_133433

Adding Scene Sound Effects

Using the Editor to Add Scene Sound Effects

Scene sound effects can be added to scenes in the Editor in the following way:

In the Hierarchy panel, select the object that needs scene sound effects, then click Add Component and select Sound Component.

2022-09-23_134428

After adding the Sound Component, select LSound, then select a sound file in Sound Name property. To play the sound file automatically, check Auto Play and it will play automatically at the location of the object when entering the scene.

2022-09-23_135236

Using Scripts to Add Scene Sound Effects

Adding a Scene Sound Effect to the script requires obtaining an object to add the sound effect, and we can do this by prefilling the String Tag property of the object that needs sound effects with the tag in the Editor.

2022-09-23_140728

In addition, add a script component LScript and configure the corresponding script for it in the Script File.

2022-09-23_142004

image-20230328152309931

Then you can select the object in the script by using prefilled String Tag, below is the object code we obtained through String Tag. The first parameter is the object tag, the second parameter is the object type and the function can be used to find the object with the specified string tag from all objects of the specified type.

--Query objects by Tag
local function get_object_by_tag(tag_name, class_type_name)
local lscene = nx_value("lscene")
if not nx_is_valid(lscene) then
return nx_null()
end

if tag_name == nil then
return nx_null()
end

local tag_table = lscene:QueryObjectListByTag(tag_name, class_type_name)
local tag_count = #tag_table
if tag_count == 0 then
return nx_null()
elseif tag_count == 1 then
return tag_table[1]
elseif tag_count > 1 then
for i = 1, tag_count do
nx_log("info, get_object_by_tag, "
..nx_string(i) .." : "..nx_string(tag_table[i].StringTag))
end
return nx_null()
end
end

Once we obtain the object, we can add the sound component to it and add it to the scene.

local lscene = nx_value("lscene")
local box = get_object_by_tag("soundbox", "LStaticMeshActor")
-- Add Sound Component
local sound3d = box:AddNewComponent("LSoundComponent", 0x00000000)

Finally, modify the path property of the sound object and load the object to add the scene sound effect to the scene using the script.

sound3d.VisBase.SoundName = "%Resource%sound\\xxx.mp3"
sound3d.VisBase:Load()
sound3d.VisBase:Play()

Adding Action Sound Effects

You can bind sound effects to character actions. The bound sound effect will play when the action plays to the specified action frame. Steps to add action sound effects are as follows:

Find the resource file of the character that needs sound effects.

2022-09-23_145130

Double-click the resource file to open the Actor Editor. The Action List on the left shows all the action entries. Among them, the action entries of Animation Sequence type (in pink) and of Montage type (in purple) can be attached with sound resources (As shown in the picture, the current action is running, which is an Animation Sequence action. Thus the sound effect will be triggered during running after the sound resource is added).

2022-09-23_145612

Double-click the action entry to enter Animation Editor, right-click the blank space on the progress bar of Notify, then select Add Notify -> Play Sound to add a sound file.

2022-09-23_145810

After adding, click the sound file and select the corresponding event for it in the Event Name of the Details panel. Then it will play during the corresponding action.

2022-09-23_150148