Triggering a SoundCue from code

Hello UE4 Gurus!

Been messing around with UE4 for a few weeks and am loving it so far! Been working on a procedural music system and so far so good although am having a few issues trying to trigger a SoundCue from a C++ Class, anyone know a good method for doing this? Looked through the Audio API and loads of Forum posts but have found nothing so far.

Any advice would be greatly apprceiated!

Cheers,

Quirk

You can either use an AudioComponent referencing the SoundCue and call Play on it.

Or you could use the UGameplayStaticFunctions::PlaySound* functions directly to play the sound.

Hi Marc, thanks for your quick reply!

So how would I set that up in my .h and .cpp files?

Would it look something like this?

In .h

FAudioComponent* audioComponent;

In .cpp

audioComponent = new FAudioComponent;
audioComponent = mySoundCue;

mySoundCue->play;

Cheers,

Q

The best example I can suggest to look at to set up your audio component in C++ is Ambient Sound actor.

UAudioComponent is the component type. And in your constructor you would set it up and then call play at the appropriate time.

If you really just want to kick off a sound at a certain point using the UGameplayStatics functions will be the easiest encapsulation of all that.

Aaah OK, cheers Marc will give that a try!