Change level music

Hello,

I have two music tracks I want to use in my level. One is the standard track that will start playing when the level is loaded and the other one should start playing when the boss is spawned. I tried placing 2 Ambient Sound actors in my level and disabled Auto Activate on the one with the boss track. I tried getting them inside my GameMode.cpp by using TActroIterator. However I cannot call the functions Stop() and Play(). I get an unresolved external symbol error. I’m not sure what include I am missing. I tried adding the AmbientSound.h header but the error is still there.

Is there another way to change level music in the way I described?

Thanks,

What I did is to add 2 Audio Components to my GameMode and set the desired tracks inside them. Then I do Play() and Stop() when I start the level and when the boss is spawned. I’m also not sure that I can stop playing a sound by using UGameplayStatics. There is a return node in the Blueprints version but in C++ it’s a void function.

You may be better off using a USoundCue rather than UAmbientSound.

Declare two variables of USoundCue inside your GameMode derived class and use the appropriate functions in UGameplayStatics to play them at the right time