Unreal Engine Blueprint – How to trigger a sound On and Off
Unreal Engine Blueprint – Trigger a sound on and off using a trigger box
This can be used to trigger a sound or music file if your character enters the trigger box.
Add an ‘Audio’ component in the components section:
When selected (on the right hand-side details panel) there are many details for it.
Add the required audio file.
Remember to turn off auto-activate in the details panel otherwise it may play on the begin play of the level.
You can also add an attenuation file here if you wish.
Add a Collision Box:
Add a ‘Box Collision’ in the components section.
Resize and position to the required size.
If you wish you can add a ‘StaticMesh’ component.
And add a mesh such as a radio or record player.
4. Adding Code into Event Graph:
In the ‘Event Graph’
Whilst this Collision Box is selected in the components panel.
In the details panel on the right hand side.
Scroll down and select:
‘On Component Begin Overlap.’
Select the Collision box again and select:
‘On Component End Overlap.’
Next, drag off from the ‘On Component Begin Overlap’ node execution pin and search for Play Audio.
Drag the audio component, from the components list, on the left into the event graph
Drag off from the Audio component variable and plug into ‘Target.’ (If its not already connected).
Drag off from the ‘On Component End Overlap’ node execution pin and search for Stop audio.
Drag off from the Audio component variable and plug into ‘Target.’ (If it’s not already connected as it may get auto added when adding the play or stop audio nodes – if so it can be deleted as two of these nodes is not needed).
The blueprint can now be added into the level in the required place.