playMaker

Author Topic: A way to play music accross scenes (but stop at final scene)  (Read 424 times)

FunD

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
A way to play music accross scenes (but stop at final scene)
« on: April 09, 2019, 07:20:27 PM »
Hi
The subject line is pretty self-explanatory.
I need a background music to play in a few scenes, but not all of them. It needs to stop after a few scenes.
Any advice?

thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4369
    • View Profile
    • jinxtergames
Re: A way to play music accross scenes (but stop at final scene)
« Reply #1 on: April 10, 2019, 08:18:54 AM »
Hi.
should music play between scenes?

if so i think you will need to load async additive.

on the scene that the sound needs to stop, when loaded, reference the object with the audio listener and use 'audio stop'
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

FunD

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: A way to play music accross scenes (but stop at final scene)
« Reply #2 on: April 10, 2019, 09:35:56 AM »
Hi,
Thanks for the tip. This seems like a nice way to do it.

And yes, it should play between scenes, but stop at the final scene.

So this is what I tried (there are screenshots below too):
- I tried to make the background music start when loading Scene 1 (which comes after the beginning scene)
- On the beginning scene there is a UI 'Play' button with an FSM
- After clicking the 'Play' button it sends an event 'Load Scene'
- Which leads to State 2, I had a simple 'Load Scene' there (which worked fine), but replaced it with a 'Load Scene Asynch' now
- I set the Load Scene Mode to Additive
- I am trying for it to send a global event which leads to State 3
- On State 3, there is 'Play Sound'

When pressing the 'Play button' it's not loading the next scene. I wonder what I'm missing? (and it's the correct scene name I entered in 'Load Scene Asynch')

Screenshots:
https://ibb.co/Z84sjwn
https://ibb.co/tZjHDMd
https://ibb.co/mXg4Gwd

Thank you

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4369
    • View Profile
    • jinxtergames
Re: A way to play music accross scenes (but stop at final scene)
« Reply #3 on: April 10, 2019, 03:42:59 PM »
Hi.
On 2nd state i can see that allow scene activation is not checked this is why the is Done event is not triggered.

It will trigger the Pending Activation Event.

But you probably want the scene to become active right after loading.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

FunD

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: A way to play music accross scenes (but stop at final scene)
« Reply #4 on: April 12, 2019, 04:34:20 AM »
Hi,

Okay, so I'd better be using 'Is Done', using a Variable, rather than the 'Done Event'?

According to Playmaker documentation I read online, 'Done Event' is an event that should be sent once scene loading is done:
https://hutonggames.fogbugz.com/default.asp?W1443

So I'm not sure why playing the sound at the beginning of the next scene doesn't work, calling a global event with the 'Done Event'. It does load the next scene though now, by checking 'Allow Scene Activation'.

I tried having state 3 in the same FSM, but I thought maybe the problem was that the event playing the music should be in the next scene so I tried that too.

I can't get it to play the sound. So I tried also with 'Is Done' using a variable.
Then I'm not sure how State 3 that has 'Play Music' calls that variable. The created Variable can't be added in the 'Play Music' action. I tried adding separate actions to that state like 'Get Variable'... still does not work

Do you know what I'm doing wrong? Thanks :)







ch1ky3n

  • Junior Playmaker
  • **
  • Posts: 71
    • View Profile
Re: A way to play music accross scenes (but stop at final scene)
« Reply #5 on: April 12, 2019, 05:30:18 AM »
Hi.
should music play between scenes?

if so i think you will need to load async additive.

on the scene that the sound needs to stop, when loaded, reference the object with the audio listener and use 'audio stop'


Similar like this, but instead, why don’t you make:

1. A scene let’s name it AudioPlayer.scene
2. Insert only audiosource , remove the camera
3. On the audiosource insert playmaker state with set game object > This object to Global Variable “MUSIC PLAYER” and save it

4. Now on scene 1, load async AudioPlayer.scene
5. This will set global variable “MUSIC PLAYER” = audiosource that contain your clip
6. Audio Play MUSIC PLAYER. This will persist as long as you don’t remove the scene
7. On the final scene, simply stop the “MUSIC PLAYER” or unload the scene

Basically you make a dedicated scene that serves as your jukebox.

Good luck

PS: this is probably not the best method, but it should works.
« Last Edit: April 12, 2019, 05:36:46 AM by ch1ky3n »

FunD

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: A way to play music accross scenes (but stop at final scene)
« Reply #6 on: May 23, 2019, 03:03:54 PM »
Hi,

Sorry for the delayed response. I hooked it up as you described, hopefully did it correctly. The problem is I can't call a game object in the second scene via the 'audio play' if it's not  a game object in the current scene, although I set it to global.
Here are some screenshots:
https://ibb.co/vLygFvp
https://ibb.co/kSGwVSr





Hi.
should music play between scenes?

if so i think you will need to load async additive.

on the scene that the sound needs to stop, when loaded, reference the object with the audio listener and use 'audio stop'


Similar like this, but instead, why don’t you make:

1. A scene let’s name it AudioPlayer.scene
2. Insert only audiosource , remove the camera
3. On the audiosource insert playmaker state with set game object > This object to Global Variable “MUSIC PLAYER” and save it

4. Now on scene 1, load async AudioPlayer.scene
5. This will set global variable “MUSIC PLAYER” = audiosource that contain your clip
6. Audio Play MUSIC PLAYER. This will persist as long as you don’t remove the scene
7. On the final scene, simply stop the “MUSIC PLAYER” or unload the scene

Basically you make a dedicated scene that serves as your jukebox.

Good luck

PS: this is probably not the best method, but it should works.

FunD

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: A way to play music accross scenes (but stop at final scene)
« Reply #7 on: May 23, 2019, 03:40:33 PM »
Quick update:

I found a really easy way for the music to play across scenes. You just create a GameObject and add 'Don't Destroy On Load' action, by dragging this gameobject. The child of this GameObject is the soundtrack.
However, I don't know how to make the music stop.

What's the opposite of 'don't destroy on Load' if there is one I can add to the last scene?
thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4369
    • View Profile
    • jinxtergames
Re: A way to play music accross scenes (but stop at final scene)
« Reply #8 on: May 24, 2019, 03:59:39 AM »
Hi.
Probably from a different object/fsm, find the object then 'destroy object'
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

FunD

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: A way to play music accross scenes (but stop at final scene)
« Reply #9 on: May 24, 2019, 04:57:09 AM »
Oh ok, I just added a global variable to the soundtrack, like mentioned above. I just had problems accessing the global variable, but I got it now. thanks for all the help!
« Last Edit: May 24, 2019, 05:00:50 AM by FunD »