Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Steven-Walker · Dec 07, 2011 at 07:44 PM · timepause

How to pause a game?

Here's the problem: I'd like to pause the game but still have my menus work. If I set time.scale = 0.0, it pauses everything in the game, including my animated menus (which are game objects).

Ideally what I'd like to do is set the time scale for groups of objects or layers in the scene, but as far as I know that's not possible.

The only other choice I can think of is to do it by brute force through scripting, which is an ugly prospect. My game has a lot of complex behaviors that trigger each other with timed delays. I'd have to intercept all of those delays and rebuild them from the point they were paused, which opens the door to a lot of potential bugs.

Is there some other approach I'm overlooking?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cj_coimbra · Dec 07, 2011 at 07:57 PM 0
Share

In a previous project I had a gameobject with a single script to handle game pausing. Others would read his state in order to do their logic or not. But as you stated that you have timers and stuff that might get too messy since you would need to track the pause time and discount it from your other time calculations.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Steven-Walker · Dec 07, 2011 at 11:51 PM

The solution I've chosen is to pause the playback of key elements via script and to leave the time scale untouched. This involved creating a handler for time triggers that keeps track of every trigger. When the game is paused, all active triggers get stopped and their current times recorded. When the user resumes the game, all of the triggers are recreated from the time it was paused. Any behaviors/animations that started before the pause continue to play, but new ones won't trigger. So in effect, the pause is a 'living hold', which in some ways is better than a 100% pause.

Thanks WillTAtl for your help.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by WillTAtl · Dec 07, 2011 at 08:38 PM

assuming they don't use physics, you can make your gui objects immune by just calculating the real time elapsed using Time.realtimeSinceStartup; there's no equivilant realtimeDelta, but you could calculate your own by storing the realtime of the previous update in a variable. Something like this...

 private var prevTime:float=0;
 function Update()
 {
     var timeNow=Time.realtimeSinceStartup;
     var deltaRealtime=timeNow-prevTime;
     prevTime=timeNow;
 
     //then write your existing code, using deltaRealtime instead of 
     //Time.deltaTime or timeNow instead of Time.time for any lerps or other
     //time-based calculations
 
 }

This could potentially cause issues if your framerate drops significantly, and realtime gets way out of synch with game time, but depending on what you're doing with the gui objects it may not be a real problem.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Steven-Walker · Dec 07, 2011 at 08:43 PM 0
Share

What about animations and using WaitForSeconds? $$anonymous$$y menus/navigation have animation tracks and I use yield to time the opening and closing of items.

avatar image WillTAtl · Dec 07, 2011 at 08:50 PM 0
Share

you could fairly easily implement a WaitForRealSeconds() function, like this:

 function WaitForRealSeconds(seconds:float) : IEnumerator
 {

     var waitUntil=Time.realtimeSinceStartup+seconds;

     while (waitUntil>Time.realtimeSinceStartup)
        yield;

 }

then in your time-immune functions, just yield to that ins$$anonymous$$d of WaitForSeconds(). This is even more prone to giving wonky behavior if your framerate drops very low, but if it's just menu open/close effects, the worst case should be that with framerate low enough the player can't see the animation, and it seems to happen instantly.

avatar image Steven-Walker · Dec 07, 2011 at 11:49 PM 0
Share

I've decided that getting all my UI behaviors to work without time is too difficult. I'm not just using yields, but also iTween and animations, which pose much more complex problems.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Is It Bad To Have Your Jump In Update()? 3 Answers

pause timer or player using Time.timeScale 1 Answer

Pause Game When Function Is Enabled? 3 Answers

Interpolating from one color to the other repeatedly 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges