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 Hamesh81 · Jan 29, 2013 at 12:04 PM · cameraprefabpausetimescale

How to pause only specific objects/prefabs?

I would like to be able to pause my game via script, but leave specific prefabs (in this case my camera) not paused and moving as per normal. Here is the scenario:

When my character gets a certain distance from an enemy I would like to be able to pause my game (for a specified time) BUT not pause my camera so that it can turn towards the enemy while everything else is paused. I've been looking at Time.timescale and using it for the "pause" functionality but I don't know how to pause everything except the camera. Would something like this be possible?

Comment
Add comment
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

3 Replies

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

Answer by Berenger · Jan 29, 2013 at 12:27 PM

You could use a custom Update function on everything that need an Update and can be paused, something like :

 public abstract class MonoPause : MonoBehaviour // Any resemblance to lady stuff is purely coincidental ...
 {
     public bool pause = false;
     
     private IEnumerator Start()
     {
         while( Application.IsPlaying )
         {
             if( !pause )
                 DoUpdate();
                 
             yield return null;
             
             // You could even have a time variable here
         }
     }
     
     // That's where it happens !
     protected abstract void DoUpdate();
 }

and ...

 public class Pouet : MonoPause
 {
     protected override void DoUpdate()
     {
         // Movement and stuff
     }
 }
Comment
Add comment · Show 4 · 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 Hamesh81 · Jan 29, 2013 at 03:12 PM 0
Share

So there's no way to apply a time.timescale to only specific prefabs for example?

avatar image Berenger · Jan 30, 2013 at 08:18 AM 0
Share

Not right away, Unity's timeScale will affect everything using time, or deltaTime. You'll have to go through something similar to the code above to have a more detailed time.

avatar image Berenger · Jan 30, 2013 at 08:20 AM 0
Share

Nop, Unity's timeScale affect everything using time or deltaTime. You'll have to go through something similar to the code above for a finer handling of time.

By the way, you don't interact with prefabs ingame, only instances of them ;)

avatar image Hamesh81 · Jan 30, 2013 at 02:50 PM 0
Share

I found a similar question here:

http://answers.unity3d.com/questions/222499/stop-time-for-specific-objects.html

It uses a timescale very close to zero and then multiplies the needed component variables by the inverse (see the link above for more details). In my case I think this is a more straight forward approach since I only ever need one object "unpaused" during the pause. I was hoping that with the release of Unity 4 there would be a more elegant way to do this but I guess these 2 are still the only options at the moment.

avatar image
1

Answer by wowza · Aug 20, 2014 at 06:18 PM

I think you should use time.fixedDeltaTime instead of time.deltaTime, that makes the prefab ignore the timescale==0. I'm only a beginner and this happened to me once, I hope I helped.

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
0

Answer by buckius82 · Nov 24, 2015 at 07:26 PM

@Hamesh81 @wowza @Berenger

hello i am writing an RTS i wanted to be able to pause only the scene not the camera.

i have a time manager script were i can set the time scale to zero which is perfect. however it paused the camera as well.

when you set time scale to 0 fixedupdate is never called on all monevelopements

  • all of my input for the camera was in the fixed update

  • all smoothing was done by using time.deltatime

to make the camera move independent of the time scale i changed the fixedupdate to lateupdate.

then instead of using time.deltatime for smoothing the input i used time.unscaledDeltaTime

using unscaled delta time also allows you to x2, x10 the scenes scale and keep the camera's movement seperate.

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

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Orbit camer while paused? 1 Answer

Unity 3.5.7 - 4.2 upgrade: Changing Time.timeScale causes OnTriggerExit & OnTriggerEnter handlers to fire 1 Answer

How can i pause gradually from timeScale 1.0 to 0.0 over a second? 1 Answer

Dramatic Camera effect with all physical gameobjects paused? 0 Answers

Set Timescale to 0 for game, except for pause menu 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