Forum rules - please read before posting.

Timeline audio track keeps playing on pause

Hey Chris,

I have a timeline that runs on game time update method

It has several tracks: speech, camera, animation, activation and audio.

When I pause the game during a timeline, all these tracks are paused but the audio continues (if the audio had already started that is)

I tried creating a new sound+audio source with deselecting play on pause and attaching that as the audio source on timeline.

my music storage has play on pause enabled; but obviously I want the music on timeline to pause otherwise it gets out of sync with other tracks

what I understand is setting timescale to 0 doesn't pause already started audio

Do you have any suggestions?

Thanks

Comments

  • What audio exactly is playing? From a Unity Audio track, or from AC via a Speech track?

    I tried creating a new sound+audio source with deselecting play on pause and attaching that as the audio source on timeline.

    You mean the Play while game paused? option? What was the result of this?

    If that still results in it playing when paused, it may be a Unity issue - since that option is directly tied to the AudioSource's ignoreListenerPause property. What are your Unity and AC versions?

    If need be, you could look into hooking into the OnEnterGameState / OnExitGameState events to manually pause/resume audio tracks played via Timeline, but I shouldn't think that would be necessary - the 3D Demo also uses Timeline for its music and doesn't have this issue.

  • Hey Chris thanks for the reply

    I just tried the 3d demo and it's also there

    I am sending you the video recording (incase you don't want any video recording here)

    the intro1 timeline starts, and if you pause after the audio has started, the music continues to play and completes when paused so it's out of sync with the rest of the timeline when you return from the pause

    I think this should not be the intended usage and should also pause the audio tracks on pause

  • Recreated - I'll look into it.

  • So far as I can tell, this is an issue with Unity. I've filed a bug report, but will update here if I have anything more to share.

  • thank you

    In case anyone else needs I couldn't find any other solution and this is a silly method I use at the moment

    just attach this to the timeline with an audio track. also needs an audio source component that's attached to the timeline tracks

    `
    using UnityEngine;
    using AC;
    using UnityEngine.Playables;

    public class TimelineAudioPauser : MonoBehaviour
    {
    PlayableDirector director;
    AudioSource audioSource;
    AudioClip clip;
    float pausedTime;

    void Start()
    {
        director = GetComponent<PlayableDirector>();
        audioSource = GetComponent<AudioSource>();
    }
    
        private void OnEnable ()
        {
            EventManager.OnEnterGameState += OnEnterGameState;
            EventManager.OnExitGameState += OnExitGameState;
        }
    
        protected void OnEnterGameState (GameState gameState)
        {
            if (gameState == GameState.Paused && director.state == PlayState.Playing)
            {
                clip = audioSource.clip;
                pausedTime = audioSource.time;
                audioSource.volume = 0;
            }
        }
    
        protected void OnExitGameState (GameState gameState)
        {
            if (gameState == GameState.Paused && director.state == PlayState.Paused)
            {
                audioSource.clip = clip;
                audioSource.time = pausedTime;
                audioSource.volume = 1;
                audioSource.Play();
            }
        }
    

    }
    `

  • edited August 2020

    Looks good, thanks for sharing. I'll see about including it in the AC wiki.

    Edit: done.

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.