So, I have music available for multiple events that happen in game. I don’t know exactly how to program it so that when an event happens, the music changes to a new song without overlapping.
For example, when my character dies, I want the music to completely stop and play the song I have for when they die.
Or when a guard is alerted, switch songs to an alerted theme, and when all the alerted guards are dead, the first song that was playing starts playing again.
Now for the coding:
To play a sound you need to trigger them by events. The Event BeginPlay triggers a sound when the level starts, and I use the audio component and a play node to play the default sound set in the audio component:
I will now setup a custom event that will stop the music, change the music, and play the new music:
I can now call the custom event function and add it anywhere where I see fit. This is done like this, right-click and search for the event you created. The red marking around the node is to showcase how it looks once you add it: