Forum rules - please read before posting.

Music Across Scenes - How to Stop?

Happy New Year, everybody!

I'm sure this is probably just something obvious I'm not thinking of, when I play a piece of music across scenes, how can I stop it? 

The problem, of course, is that the object doesn't exist beforehand in the scene that I want to stop it in - it's just being carried over from the previous one.

If there's no answer to this, it won't be killer to fade my music out at the end of a scene and then quickly fade it back in again from the top at the beginning of the next one, but it'd be nice to be able to do it across scenes and then have a command to stop.

Comments

  • It should be easier than this to do, but you should be able to do it by prefabbing the Music object, adding a ConstantID script to it (checking Retain ID in prefab), and referencing that when turning the music off.
  • Gave this a shot and wasn't able to make it work, unfortunately, but it's a very minor thing for me.

    Will maybe incorporate it down the road once you get it working as easily as you'd like it to...!
  • Hello Chris and AC community,

    I would like to update my answer above: After suddenly realizing that I was doing this completely wrong, I did it correctly instead.

    What Chris suggested above works just fine!

    Carry on.


  • @ChrisIceBox

    Hi, sorry to dig up an old thread, but I am having trouble doing this exact thing. When I move my Sound Object to a prefab outside of the scene, and add the ConstantID script with the Retain in prefab ticked :  I cant then access it anymore within the scene's action list (sound:play) to play OR stop it. 

    I am also trying to stop a playing sound carried over from a previous scene.

    Thanks !

    Tom
  • Hi @Tom,

    Check that the Constant ID number on the prefab and the scene object are the same - if you added the prefab before the script, then it may be that the values are different, and you'll have to click "Revert" in the scene object's Inspector to re-sync them.
  • Hi @ChrisIceBox, thanks for the reply.

    I checked the numbers and they are the same, but the music still doesnt stop. 

    Just to double check: I have the sound object in each of the two scene folders AND as a prefab outside the scene folders. All have the same ID, and all have play across scenes checked. 

    I have a sound play action (with loop) in the first scenes actionlist, and in the next scenes actionlist there is a sound fadeout action on the sound object with the same ID. 

    Am I setting up the prefab wrong?
  • You don't need the Sound object to be in both scenes - just the one that the player enters first.  I think what's happening is that the "Sound fadeout" Action is getting confused about which one to affect - and is controlling the one that isn't playing (since there'll be two in the scene at the time it's run).
  • Yeah thats what I thought, but if I dont have the sound object in the scene then the Sound:Play action wont let me search for the prefab object.


  • It should do: when dragging in your new asset file into the "Sound object" field, it should list the object's Constant ID number beneath it.  Are you using the latest version of AC?  What does your field show instead?
  • Aha yes that worked. I had no idea you could drag assets into the actionlist sorry. I was only going by the search tool that pops up when you click on the sound object field. And prefabs dont show up there.


    Thanks so much Chris, im glad it was a simple answer :)


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.