Download

Reset everything BUT sound?

Currently the way I reset my levels is calling the “Restart” command in a blueprint node.

But I’d like to restart my level and also let my music continue playing from the point it’s at before I press Restart.

Is this possible and how would I do that, if so?

I had a quick look, but couldn’t find anything clean. So perhaps you can one of the following:

  1. Spawn a sound and use a float variable to keep track of how long it has played by adding GetWorldDeltaSeconds every Tick. You must store the float in a blueprint derived from GameInstance since that’s the only class that maintains state from start to end. On restart get the value at which the float went up to and start your sound from that point - you can set the starting point in the spawn sound at location node.

  2. Don’t use restart. When you’re done with your actor just make it not visible and disable collisions. When you want to restart just put everything back into its initial state. This solution might be better since I suspect the first solution will give your sound a noticeable cut, whereas this shouldn’t.

I tried to do the second thing but it caused some weird issues the next time I died and had to restart so I was wondering if there was another solution.

Would it be possible to handle the music in the GameState or does it have to be executed by the level?

It just needs to start when the level is loaded and then continue after a restart.

So, it looks like restarting a level just unloads it and reloads it. There are a bunch of posts about continuous music in the forums and AnswerHub, but it doesn’t seem like a feature as of yet. There is a feature request though.

You might consider setting up a Persistent Level if you won’t have user-made levels.

I won’t have user made levels no. But how do you mean a persistent level? One that never restarts?

Not really a pro in this area, but this may help: how to make persistent level? - UE4 AnswerHub

From the sounds of it, you actually do level streaming, and the “master” level is the persistent level with sub-levels that you load and unload. The Level Streaming and World Composition guides hit on this a little more in detail: https://docs.unrealengine.com/latest/INT/Engine/LevelStreaming/index.html

I suppose I’ll check that out. Thanks!
Do you know if it works for mobile though? My game is a mobile game.

Level Streaming should work on mobile games. I don’t see any reason why it wouldn’t, but won’t say that with 100% confidence! :stuck_out_tongue:

You may want to watch how much you put into a single level for performance reasons though.

Really what’ll be there is a character, two placed blueprint actors and then the game spawns new actors as the game goes on at random but those actors are destroyed when they touch one of the placed blueprint actors a few seconds later.

Then performance probably won’t be that huge of an issue, unless your level and actors are high-poly. Still, with level streaming, you may run into performance issues after a while, depending on how much you pack into a level. Give it a go and let us know how it works out. Good luck! :slight_smile: