Search Unity

Feature Request for Better Pause Functionality

Discussion in 'General Discussion' started by Braveo, Aug 5, 2021.

  1. Braveo

    Braveo

    Joined:
    Oct 26, 2016
    Posts:
    2
    Pause functionality is very strange in Unity compared to other engines.
    - Godot allows you to pause specific nodes, and
    - Unreal allows you to set the game paused with a node.

    Unity's most viable/popular one is setting Time.timeScale to 0 and manually disabling function callbacks in different scripts. Enabling and disabling GameObjects is definitely another option but that wouldn't work well for the objects that rely on OnEnable and OnDisable.

    I wish Unity had a simpler way to implement pause states, whether it is with root GameObjects or Scenes.
    It's not an absolute must-have since we always have workarounds, but it would be an extremely good quality of life feature to have, especially considering that other engines have some built-in pause states already.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,153
    Do you have an approach that would fit as many use cases as possible? Because that's the catch with asking the engine devs to write the system for you. Whatever they come up with is going to have to cater to as many people as possible and if it just so happens to not fit your needs that's just how it'll be.

    Instead of manually disabling function callbacks just have a static class or singleton with a public-facing boolean that you check before you allow execution to continue.
     
    Last edited: Aug 5, 2021
    MadeFromPolygons likes this.
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Setting timescale to 0 is not always good way to do pausing, as it will impact systems reliant on time.

    Its better to write your code so that it checks if the game is paused, and returns before execution if it is - this way you can control what is affected by pause and in what way - as well as execute specific logic on pause (such as stopping physics actors from moving etc)



    Code (CSharp):
    1. void Update()
    2. {
    3. if(isPaused) return;
    4.  
    5. // do stuff here that should run if not paused, like moving players etc
    6.  
    7. }
    Ofcourse lots of people do it in different ways, but this is what we use in enterprise production projects we have and it works very nicely without any ramifications. If you wanted to have say something moving with physics on a paused screen or while paused, that is possible with this approach. Timescale = 0 would not allow that.

    If you have lots of physics going on at any one time (too much to manually grab them all and freeze during pause, and then reinstate physics forces on unpause) or just want a simple solution, then timescale = 0 is fine ofcourse :)
     
    stain2319 likes this.
  4. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    In the long run convenience always wins.

    Instead of providing no options, i think it is better to provide many. 10 different ways to pause.

    People who already know still always have their own way to do it. That's not a concern. But pause is a function basically every game will use - no reason there hsouldnt be a library of simple, convenient ways to do it.

    Make a case against it all you want but in the end consumers always go where there is more convenience.
     
  5. ExtraCat

    ExtraCat

    Joined:
    Aug 30, 2019
    Posts:
    52
    Please no. The ongoing and never-ending situation with pipelines and networking advocates against more than one way of doing anything when it comes to unity solutions. It will end poorly for all consumers.
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    That's why there's Time.unscaledDeltaTime.
     
    xVergilx and ippdev like this.
  7. Gekigengar

    Gekigengar

    Joined:
    Jan 20, 2013
    Posts:
    738
    Being able to pause only specific list/layers would be cool.