Hello, I am a new developer and some weeks ago I started to develop my first game. Before I start I want to apologize about my English. English is not my main language. So, I have 10 different levels. I opened Level 1 and opened
Level Blueprint. Then i did Event BeginPlay → Spawn Sound 2D. Everything works but, I want at the last level (level 10) music to stop or play other music. And i cant figure it out how to do it. Please help me.
Okay to begin with am sorry for late reply, I kept refreshing but it was showing i had 0 answers. So I tried what you told me but it didn’t work and am pretty sure I did something wrong. Is it easy for you to give me more detailed answer? As I said I am new developer and am still learning the whole thing. Thank you.
Are you just creating the same sound on 10 different level blueprint maps that the player runs between? Or is there some other interaction being used?
On level 10, you can take the output of Spawn Sound 2D and make it into a variable upon creation.
Then you should be able to use that variable to stop the music by plugging it into a Stop node.
You can then proceed to spawn another sound if you want different music. Also, you can even set that same variable off of the new sound to do things with if you don’t think you will ever use the old sound again.
I only have a “Event BeginPlay → Spawn Sound 2D” on the level 1 at Level Blueprint, and it keeps playing as i switch levels. I have also a persistence level (if I say it correctly). I dont know if it affects the other levels.
Did you call the event? ( just checking )
No, where should i call the event? on level 1 or 10? Also when I call it I need to do ‘’ Event BeginPlay → " and thats it? I’m having trouble to understand custom events am sorry
If I read this right, normally the sound stops when you unload the level, but when you get to the end of level 10, you want the sound to continue?
You call this event when you know that you’ve finished level 10 and you’re ready to unload it.
It doesn’t matter if you call it in level 10 or from the persistent level.
Ok, I have to know which node you used to start the music on level 1.
Basically, it has to be ( or needs to be change to ) a node which produces a reference. Let me explain.
These are no good:
These are good:
because they produce a reference. So, whichever one you use ( it may be one I haven’t mentioned ) start the music like this:
then later, you can stop it like this:
Its actually the opposite, when i run the levels the music plays and i want to make the music stop at the 10th level. Let me explain. I created a game music that its not on loop by itself and i enabled loop so the music will play for ever untill the player goes on the 10th level that will be the ending. And I have the main menu perfectly working with its music and some how when i click “play” the main menu music stops and the music for the game starts but when I go to the 10th level the music not only keeps playing but if i place another music it will play both of the music. So i want the music I added in Level Blueprint (level 1) to play through these 9 levels (which it does) and stop when the 10th level starts. I hope you can understand me.
sure get as much time as you need thanks a lot for your help
Okay so i cant really make the “my music” variable to have the target under “my music”
Thank you so so so so much, it worked! I’ve been trying to figure this out for days now! I can’t thank you enough!
Okay so “my music” that you created is a variable?
If yes, then if i create this variable in level 10 then this should not exist in level 1 right?
I dont know if i explained it well, but, the levels are not in the same map. The levels / map changes with a box collision and a blueprint that says “open level” and then the name of the level.
No, sorry we’re not quite there yet!
How are you playing the music currently? You said the music runs fine through the levels, how did you start that playing?
Ahh…
hold on…
it’s a bit more tricky, because you spawned it, and now you don’t have a reference.
Let me experiment, gimme 10…
bin that variable.
pull the ‘as my game instance’ pin and look for ‘set my music’
( the variable is in the game instance )
Here’s the answer, use a game instance. When you start the sound, level 1, do this:
Then, later in level 10, you can say:
To make a game instance, just right click in the content browser, choose BlueprintClass and then choose game instance:
When you make it, call it MyGameInstance, if you to follow the code above. All you have to do is put the variable in the game instance like this:
It’s type is Audio component object reference.
You’re welcome
Please tick the answer, it will help others.
I think I ticked it (am new to the website too so correct me if I’m wrong). Again thank you so much, I hope I didn’t waste too much of your time!