Forum rules - please read before posting.

Sound component bug

I have several audio sources with a "Sound" component attached. The Sound component's relative volume is set to 0.14 (but it could be any number, really). When I enter Play Mode, the volumes of all audio sources in the scene are adjusted correctly according to their respective relative volumes.

However, if I enter the scene by switching scenes instead of starting the game there, the audio sources that have "Play while game paused?" checked will have their volumes set to 1, ignoring the relative volume I set. If this is unchecked, there is no issue.

Comments

  • Hm, never mind! I thought I got it working by unchecking "play while game paused?", but now even when I uncheck it, this doesn't seem to be working when switching scenes (if I enter Play Mode directly into the scene, it still works fine). Any idea of what to look for? I'm using this sound source to play a Timeline audio track.

  • Right, so I created an entirely new audio source, assigned an AudioClip to it and checked "play on awake". There's no mixer group or any logic affecting this audio source. Then I added a Sound component to it, selected "Music" as the sound type, and set the relative volume. This results in:

    (1) If I enter play mode directly into that scene, the volume is set correctly.
    (2) If I enter play mode into that scene, switch scenes and then come back, the volume is not set correctly when we return (full volume instead).
    (3) If I enter play mode into a different scene and switch to the scene with the audio source, the result is the same as (2).

    Then I added a Remember Sound component to the audio source:

    (1) If I enter play mode directly into that scene, the volume is set correctly.
    (2) If I enter play mode into that scene, switch scenes and then come back, the volume IS set correctly when we return due to the Remember component.
    (3) If I enter play mode into a different scene and switch to the scene with the audio source, the volume is not set correctly (full volume instead).

  • edited February 2023

    As a workaround, I'm currently bruteforcing this by setting a "Change volume" action in the scene's OnStart actionlist, but this renders the Remember component useless.

    Something I've also noticed (though it is less of an issue) is that even when entering the scene directly, the Sound component takes a couple of moments to set the volume to the correct relative volume. This results in a split of second of loud music before the correct adjustment. This doesn't seem to happen when the remember component is the one setting the volume, though - meaning it's probably loading first?

  • edited February 2023

    After fiddling with this a bunch, I've realised I'd avoided these issues so far by leaving the audio sources off and then fading them in whenever I entered the scene (then the relative volume was taken into account correctly).

    The issue only became apparent now because I decided to synchronise the background music with some actions in-game (i.e. the lumberjack will only chop wood on the beat), so I needed to use Timeline for that, and the action used to play a timeline doesn't update the audio source volume at all, which was a problem in a number of situations (as described above).

    The way I ended up testing all this after I noticed the issue (with a simple "play on awake" audio source) meant I once again bypassed any actions that force-updated the relative volume (like "Fade in"), making the on start issues more obvious

  • edited February 2023

    Much of this seems related to the "Play On Awake" checkbox, which is part of the Audio Source's built-in behaviour.

    When this is checked, it will start playing immediately when the scene begins - which may be before AC has finished initialising (and can then set the volume appropriately), depending on how the scene is opened.

    The best way to make sure that the volume is set before playback, uncheck Play On Awake and instead use a Cutscene that runs when the scene starts. If you have multiple such audio sources, it may be easier to bypass "OnStart" with the ActionList Starter component, attached to the AudioSource along with a Cutscene that runs a single Sound: Play Action.

    Though, this may only be part of the picture. Do any of the above issues persist after this change?

  • Yes, that's what I gathered! As you said, when dealing with audio, it's best to just let a cutscene initialise everything with the Sound: Play action (or Fade In). As well as avoiding the early loading of audio before AC has initialised, those actions seem to make the relative volume setting kick in.

    The issue I still have is related to using Timeline when the audio track is linked to an Audio Source. If you run the Engine: Control Timeline action to play a timeline, this will not update the associated audio source to reflect the relative volume set by its Sound component like the Sound actions would have done.

    This is when the bug I found becomes apparent: when you enter Play Mode, all audio sources in the scene will have their volume updated according to the Sound component settings. But if you enter the scene after switching from a different scene, these settings will not be updated at all. This is not a problem if the Sound: Play action is going to update them anyway! But since the Engine: Control Timeline doesn't do that, audio played by a timeline won't respect the relative volume settings in this case.

  • Thanks for the details - I'll look into it and let you know if I need anything more to go on.

  • Recreated. To fix, add the following to the end of the Sound script's OnInitialiseScene function:

    SetMaxVolume ();
    
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.