Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Setting Time.time to 0 pauses all timeline tracks except from audio

Discussion in 'Timeline' started by crdmrn, Dec 16, 2018.

  1. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    53
    As the title says, I'm setting Time.time to 0 in order to pause my game, as well as AudioListener.pause to true to pause all sounds. But this has no effect on the audio tracks of my timeline, which keep on playing regardless of everything else. It feels like it's an unwanted behavior, or that I'm missing something... anyone got an idea? ^^"
     
  2. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,126
    You should never set time.time to 0 for pauses. That is a terrible way to do pausing. You should have a flag, lets call it IsPaused, that you enable disable when pausing/unpausing. Then do a check in all logic against this on anything you want to not happen when paused.

    Code (CSharp):
    1. if(!IsPaused)
    2. {
    3. //Do stuff that is pausable here
    4. }
    5. else
    6. {
    7. // here is what happens when paused
    8. }
     
  3. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,014
    How would you pause things you don't really have control over, such as Physics, Animation, Particles and so on...?
     
  4. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,126
    I would actually pause those, using stuff like https://docs.unity3d.com/ScriptReference/ParticleSystem.Pause.html etc

    Rather than flipping one big switch and hoping that the right systems are being paused, and the right ones are being left running which is what setting time.time = 0 is like.

    Here are some good discussion around the topic:

    https://answers.unity.com/questions/174448/stop-physics-without-using-timetimescale-0.html

    Edit: but essentially, if you bind everything to that flag, it should be easy to disable/enable/pause any behaviours you require. This includes stopping animators and timelines, pausing audio sources etc.

    On our big scale projects we normally make a pause manager for this purpose that helps keep track of what requires what level of activity during pause, and sets things back when unpaused
     
    Peter77 likes this.
  5. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,014

    Overwriting actual state of objects and then having to restore it afterwards, sounds pretty error prone to me.

    I've never had issue with Time.timeScale=0 though. What problems did you run into try to solve by not using Time.timeScale=0? I would like to know/understand those issues, so I can doge them in the future.
     
  6. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,126
    Anything that requires behaviour to continue, so if you want any animations to play when paused such as an idle animation etc they wont work. Most of our applications are simulations which require stuff to execute over time even when paused in the background so they have always required a proper pause procedure.

    If you want literally everything to stop, as if the game is frozen, then sure timescale is a perfectly fine solution. But its still better to actually track what your doing and manage it yourself. And no its only error prone if you dont understand what your own code is doing, As in if you have a good handle on everything, such as what a manager will give you, then it is no issue, or at least no different to keeping track of any other collection of objects and their states.
     
  7. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,126
    EDIT: @Peter77 I should clarify and say that the method I recommend only is better over yours if you specifically need things to continue to happen during pause. If not then you should just use timescale as it is a quicker solution to implement :)
     
  8. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,014
    Every game I worked so far, needed to stop every ingame stuff on pause, so I probably never ran into this issue.

    For animations and sounds inside the pause menu that need to run even if timeScale=0, I just configure the UI Animator to use UpdateMode=UnscaledTime and the AudioSources to use AudioSource.ignoreListenerPause=true. This by-passes timescale, allowing me to have animated menus when the game is paused, thus was never a problem for me.
     
  9. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    53
    I couldn't have explained my reasons better, so thanks a lot for doing this for me :D

    That said, I still need an explanation to my original question which is why do Time.timeScale = 0 stop everything except audio tracks in a running playableasset?
     
  10. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    644
    Because audio always runs against the DSP clock, even when the timeline is set to use game time. Switching the timescale to 0 doesn't trigger it to 'pause'. It probably should though.
     
  11. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,014
    I don't think it should. To comply with how other Unity systems work in my experience, audio should pause if the AudioListener.pause flag is set to true. Audio output isn't bound to Time.timeScale in Unity as far as I know.

    https://docs.unity3d.com/ScriptReference/AudioListener-pause.html
     
  12. scottnc27603

    scottnc27603

    Joined:
    Jul 20, 2014
    Posts:
    2
    I have a training application and I want the user to be able to explore the scene and have the audio playing the entire time whlie the Timeline is paused. I want to control the animations based upon user interactions with the scene. I'm trying to use the Timeline to halt the state of the scene until the user clicks on a certain item within the scene. I've seen where people are suggesting an alternate method of pausing the scene(Time.time is now read only so this is out of date with my version of Unity), but I'm still not sure how to do this. I'm probably missing something easy, but I'm new to the Timeline. TIA, Scott
     
  13. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    53
    @seant_unity @Peter77 As I mentioned in my first post, I'm also using AudioListener.pause to pause all sounds, but that also has no effect on the Timeline's audio tracks (while it works as intended for all the other audiosources in the scene). So I guess whether I'm missing something, or it's a bug.
     
  14. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,014
    It sounds like a bug to me.

    I would submit a bug-report with a project to reproduce the issue, as described in this document:
    https://unity3d.com/unity/qa/bug-reporting

    Submitting a bug-report allows Unity Technologies to take a look at this issue.

    After you submitted the bug-report, you receive a confirmation email with a bug-report Case number. You can post this Case number here (in this forum thread) for Unity staff to pick up, in case they see your post.
     
  15. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    644
    @crdmrn That does sound like a bug. AudioListener.pause controls the DSPtime which should affect timeline. @Peter77 is spot on, a bug report will allow us to investigate.
     
    Peter77 likes this.