Switching Sound/Music when clicking on an Object

Hi Guys,

I want to have a Music Receiver in my scene and if I klick on that it should first play an audio track and if I click furter it should switch to the next track and so on. On Off funktion would be nice too.
I have set up a soundcue with a Switch in it and 3 Songs.
Are their any tutorials about this topic, or are you able to help me?

Thx a lot

Hi, here’s a simple setup that’s based on what you already have, and will do the job:

In your receiver’s Blueprint add an Audio Component (“Music” in my screenshot)
Set its Sound to be your Sound Cue

To toggle Play / Stop -
On the UI event (I used Space Bar) you’d want to call Fade In / Fade out on that Audio Component

To switch to the Next / Previous track -
Add an Integer variable and name it the same as the parameter in your Switch node (“Track” in screenshot)
On the UI event (I used Right / Left arrows), if track number is within range,
Increment / Decrement that Integer and Set Parameter on our Audio Component
Then Fade it in with the new track.

Some notes on this setup:

  • Switching tracks also plays them right away
  • Tracks always start over from the begining when selected
  • If you want the sound to appear to come from the speakers, try setting the Attenuation Distance Inner Radius
    to at least their distance from the receiver, and set Spatialization 3D Stereo Spread to that distance as well.

Good Luck !

Thx a lot! I will try it.

Hi, do I have to make “EventBeginOverlap” or something?
It won’t work.

Hi, sorry for the delay… strange days :-/

The first thing to stop it from working is in the SoundCue -
You need to connect a WavePlayer to the ParameterUnset pin as well,
It’s like a default sound to play, for that matter.
Have your first Wave node Output wired up to **both **that first pin and to index 0 pin.
If it’s still not happening, perhaps an input issue ?
I’d check the receiver’s Blueprint > ClassDefaults > Input > Auto Receive Input > Player 0

Another matter is how it’s triggered -
As it is, the key input would work anytime/anywhere in your game world.
If you wish to limit it to certain conditions, say only when the player approaches the receiver, you may use a Gate.
The key input would then pass through and execute only when the gate is open, and you set the terms.
In the receiver’s Blueprint Add a SphereCollision Componenet
Create Events for Begin & End Overlap for that Sphere,
And connect them to a Gate like in my screenshot.
Best of luck !

PS - There’s also a post here from last week with an interesting tutorial, for a more elaborate media playing system.

Hi,
no problem, I have time :slight_smile: and thx alot again.

  • Now the Triggerbox is working, but the Music starts right when I enter my Level.
  • Than I can go into the Trigger and turn it on and off.
  • When I disconect the “parameter unset” in the Cue, than I have no Music at all.
  • The Switch between songs only switch to the last track.

Do you have any Idea why in won’t work?

Thx and Greetings
Micha

Hi, so

  • Music is probably set to be auto activated on Play :
    In the receiver’s Blueprint select the Audio Component, in its Details panel uncheck “Auto Activate” and you’re all set.

  • Track index number is currently fixed on 2, and isn’t affected by the Int Variable :
    In your Event Graph connect the “Track” node to the “In Int” pin of “Set Integer Parameter” node and you’re good to go.
    Mind you, this variable holds the track number to play, and I set the limit on incrementing to 2, because you said so -
    If you ever want to add more tracks to the playlist, just set it in the Condition node of the ++ Branch (top of your screenshot).

Hope this helps, Cheers !
Eran.

That helped me, now its working. Thx a lot!