Only Play Music When Player Is Moving

Check velocity and pause/resume the music accordingly.

If I pause it in the blueprint, will it save the current position? Is there even a way to do that?

I just started yesterday, learning the ropes. It doesn’t seem like many people have asked this, or there haven’t been clear answers to my question.

My idea is as follows: This game is a stage for my next album, and I only want music playing when the player is moving in the stage. This means I need to keep track of where the user is in the song at all times, and constantly check if there is movement. Is there a right way to do this without using a ton of CPU and RAM? I want to make this system as non-destructive as possible so people with low-end computers can play this game as well.

If you want to pause/resume song/audio based on movement, you can use a simple function to do that. I put one together quick time. Song starts to play when game starts, if you’re moving it keeps playing if you stop - music pauses and when you start moving again audio is resumed. Of course it’s very crude. Let me know if that is what you meant. It might be a starting point for you. :slight_smile:

Yeah I think I got a basic idea of how to do it- can I automatically assign a value to a variable when the game starts and change it when the branch is called in this example? (the code I’m not showing checks if the player is gaining velocity every tick)

I think I got it after some tinkering, I haven’t tested it yet, will update thread when I run it

I think you got it. Just for the sake of it I will give you my setup. It’s done inside a level blueprint. I put up a screenshot if you don’t know how to get there, but it can be done from anywhere really.

The only problem you might have now is when music finishes, then you will get errors. I couldn’t get the music to play again using On Audio Finished event from Spawned Sound but here’s a work around. This will stop the errors.

It’s quite alright, I’m not that advanced myself (self-learning). It comes with time. I was just thinking about music for my own game and you could setup a array of music files and then just fish them out of there one by one. You could randomize it that way too.
I will put together a very basic setup and post it here.

Just a simple pulling out of array. I’m not showing here how to randomize audio files or make sure you don’t play the same ones over and over and such. This isn’t that hard to do so you can give it a go.

Is there a way to make it play different audio files when this one ends? And then when it’s out of audio files can it stop playing music?

I’m very new to unreal, actually, I just started yesterday on this project. I plan to be done with this game in 4 months, so any help is greatly appreciated :stuck_out_tongue: