playMaker

Author Topic: Changing scene music  (Read 304 times)

Seiryu33

  • Full Member
  • ***
  • Posts: 133
Changing scene music
« on: November 10, 2022, 02:47:01 AM »
So I'm having trouble with this one. I want to change music depending on which scene is playing, like when transitioning from an overworld map to a dungeon and each scene having a different track. I tried using Game Object Compare so it would recognize which scene was which, but no dice. The more direct solution would be simply having the music play on each scene but I want it to play at specific moments and not sure how to accomplish this.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Changing scene music
« Reply #1 on: November 11, 2022, 11:13:11 PM »
Hi.
Have a scene or gameobject to handle the music, make sure this scene/gameobject is not unloaded/destroyed. (you can use load additive / use the action 'Don't Destroy On Load")

Create a "Music Handler" fsm.
at the start of the music handler use a "Get Owner" and set it as a global variable.

now you can set some global transitions (Music/Fade out Stop, Music/play, Music/stop, Music/Fade out Play, Music/Fade in play) to trigger from any scene/gameobject.

You can set your music into an array, or set a string array (if you want to use resources load for example) to reference.

Now from any other object / scene use "Set Fsm Int" to set the index of which music you want to play
Then Use  "Send Event" (set events global) or "Send Event By Name" to trigger Music/Fade out Play,  Music/play

For fade in /out you you can tween the volume.