Forum rules - please read before posting.

The sound across the scene duplicates?

edited April 2014 in Engine development
I'm adding sound object to the root of the hierachy. Also choose music and click on play across the scenes. Itplays on wake.

The problem is, though the sound plays on the scene and we can go to other scenes. When we come back to the room that has sound in its hierachy, the song starts again while the first song still plays. So it duplicates.

What might be wrong? How do we aproach this problem?

Thanks

Comments

  • Don't rely on the Audio Source's Play on awake box - instead, use the Engine: Play sound Action in the scene's Cutscene on Start field to play your music.
  • Ive disabled play on wake, instead created a cutscene, placed it in to settings cutscene on start. In inspector ive added action engine:play sound and placed my sound object in to cutscenes sound object input box.

    Now what i have is, the song plays across all rooms from where it left off in previous scene. However if we come back to the room the song originated, the song starts from the begining rather than continuing just like while in other rooms.

    Is this the desired result or am i missing something?

    Thank you once again :)
  • As of 1.29, this is the expected result.  Will try to improve this, but for now this is how it works.
  • Alright. Well just have to plan our scenes and musics acording to this workflow :) Thanks
  • No need - the upcoming 1.30 fixes the issue.  Basically if a Play sound is used to play a piece of looping music that's already playing, it'll be ignored.
  • Oh ok. Eagerly waiting the new update than :)
  • edited January 2015
    Chris was this ever fixed? I currently encounter the same issue. Although I do notice the changelog states for 1.30:



    -Fixed: Using the Engine: Play sound
    Action to play music causing the music to restart if the clip was already
    playing

    I have music that is to exist between scenes, has
    no parent object, is set to loop in the audiosource itself and on the
    Play Sound action, and flows just fine until I enter a scene that calls a
    Play Sound on it again and it restarts. I noticed ActionSound.cs checks
    if audioClip is the same as whats
    playing, but audioClip is the optional change of the clip itself.I assumed such a check would be in the Run() function but I am failing to see where this check would be.
  • But if you assign the clip in the Action, that would solve it, no?  That's the intended workflow.
  • edited January 2015
    You are correct if you assume that you only have one audio music file that exists between scenes. In my case I have regular music along with some ambient music that is basically background sounds.  I can't just change them to SFX or Other because then I lose the option for them to play across scenes. If you try to have two music files in this scenario, neither of them play as they both call to end the music on the other one when the play sound action is ran.

    Whats the reasoning behind only allowing one sound to play through scenes without restarting or am I the first to run into this?
  • edited January 2015
    Also I have noticed that you need the Sound object to exist in scene to play it. You can't just assign the prefab to a play action for instance. The way DontDestroyOnLoad works is that if it starts in Scene A, load into Scene B, and then load back into Scene A you now have two instances of that object.

    In this case I try an action to fadeout the music and it does not work. I presume it runs the action on the copy that is not playing. The sound objects and the prefab have the same constant ID. I feel like I am very scoped in terms of sound flexibility here. How is everyone else getting by with having a lot of scenes?
  • Rather than try to fix an exact problem, I'd be happier to hear your suggestion for improving the workflow here.  Since you're working in a practical situation, how do you think it should work?
  • edited January 2015
    Sure Chris. I gave a bit of thought before responding. Here is how I would expect these features to work.

    1.
    If I use a Play Sound action on a Music sound I expect it to play
    without affecting other music sounds. Likewise if I play two music files
    consecutively I would expect them both to play. A bool set for stopping
    all other music or not would help support both cases.

    2.
    Following #1, if a music file is already playing and I tell it to play
    again, there should be an option of whether or not to restart the sound or leave it to play at its current spot. It seems odd to have to place the
    same exact clip that the sound uses into the optional new clip field to
    prevent the sound from restarting. A play action could have a bool of
    "Restart" to indicate to restart the sound if it is already playing.

    3. I can't think of any reason why other sound files can't also exist between scenes.

    4.
    If a sound file is existing between scenes there should be a solution
    in place to remove a duplicate sound object from the new scene. One way
    to do this is on the Awake() function search for an identical sound
    object (check constant id) and if found, then have the object delete
    itself.

    Thoughts?
  • Your suggestion of a "Restart?" option is a good one, but I'm keen to simplify things as much as possible.

    I'm not sure of the bool suggestion in 1).  I see the need for it, because AC assumes that only one music track will ever get played at one time - which I think is a safe bet.  You're making use of multiple music tracks, but you've said that that's because you're having to rely on them for SFX as well.

    If SFX tracks could survive scene changes in the same way that Music tracks do, would that eliminate the need?  Music tracks would always play one-at-a-time, SFX tracks would always play independently.
  • I think that considering my other sounds as SFX is just fine so if they could exist between scenes it would solve that. The Restart bool is more of a convenience/workflow thing.

    However you didn't mention how you felt about #4. I think its quite an important part when having objects that don't destroy on scene loads.
  • Currently, a music track that's set to survive scene changes will only do so if it's actually playing at the time.  I assumed #4 was just a request to implement a similar check for SFX (though a different method), and would be done as part of #3.  Which method would be best, in your opinion?
  • I think both methods should work together. The issue I had was I start in scene A with music "1" playing. I load scene B with music "1" still playing. I then re-enter scene A and I now have two objects that represent music "1". One of the objects is playing the other is not. I used an action to fade the music "1" via its prefab's link with a constant ID and it did not work.
  • Yes, I see that now - I wasn't thinking about the "re-entering" case.
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.