I am trying to cause the level music to fade when the player dies, at the moment it just continues when he respawns when I want it to start again and fade in, this is created in the Level blueprint, however; when I try to reference the player death ‘Is Dead?’ I’m not sure how to configure the blueprint layout properly.
You can figure out how to access the music from your pawn
and fade in it on spawns begin play then fade out where you
set your variable isDead to true.
What you are doing now is adding an audio component the first time the level loads, the level doesn’t know that your player dies at some point, this branch will never fire off from True unless your boolean is set to True before the level starts.
Also it has no target which will cause it to fail to get the correct value, the other issue with the false pin is that you are playing a sound 2d and then also fading in one, it might be the same sound, but its going to play twice with this setup, once instantly and once by Fade in if the boolean is false.
As you can see in the screenshot there’s a custom event called “Player Died”, just call this event when your player dies and the sound will smoothly fade out based on the duration you’ve set. To get that Node that says SET Level 001 Music, promote into a variable from the return value of the Spawn Sound 2D.
I’ve done this inside a Player Controller, but you can do it wherever you like.
Okay so I created in the player controller so I can reference the death event, it plays/fades in when the game starts and fades out when I die, however; when I respawn the music doesn’t come back? is that because it’s attached to Event Begin Play which only triggers once? how do I fix that
It really depends on what you do after you kill your character. In my screenshot i was under the impression that you would then restart the level, that way the Player Controller’s “Event Begin Play” would fire again.
If you’re just destroying the character and then re-spawning it without reloading the level, you can store that code inside the character.
Okay so what I did to get it to a satisfactory level was add a delay at the end of Fade Out so that it just faded back in when the player began play again, which seems to work the smoothest! Thanks for your help!