Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by ccgtest · Jan 17, 2019 at 02:41 AM · fixedupdatetimescale

Time.timeScale = 0 can't stop FixedUpdate()

I set Time.timeScale = 0 in FixedUpdate(). But, FixedUpdate() can't stop immediately. Excuse me, why can't I stop immediately? Thanks for any helpful answers.

This is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System;
 
 
 public class Test_TimeScale_5 : MonoBehaviour
 {
     private int ph_frame = 0;
     // Start is called before the first frame update
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     void FixedUpdate()
     {
         ph_frame += 1;
         Time.timeScale = 0;
         Debug.Log("--FixedUpdate-- [ Time.timeScale=0 ] ----------- frame num: " + ph_frame.ToString());
     }
 }


Here is log picture: alt text

qq截图20190117102303.jpg (17.9 kB)
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 haruna9x · Jan 17, 2019 at 01:38 PM 0
Share

It stopped after 4 frames.

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by badadam · Jan 17, 2019 at 01:57 PM

When you set Time.timeScale=0; animations stop but scripts continue to run. To stop FixedUpdate running, use static bool value as the script below.

 public class Test_TimeScale_5 : MonoBehaviour {
      private int ph_frame = 0;
      public static bool isPause = false;
      private void FixedUpdate()
      {
           if (isPause)
           {
                return;
           }
           ph_frame += 1;
           Time.timeScale = 0;
           Debug.Log("--FixedUpdate-- [ Time.timeScale=" + Time.timeScale.ToString() + "], frame num: " + ph_frame.ToString());
      }
 }

And when you want to pause the script from another script, use this code below.

 Test_TimeScale_5.isPause = true;
 Time.timeScale = 0;
 


Comment
Add comment · Show 2 · 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 xxmariofer · Jan 17, 2019 at 02:01 PM -1
Share

Scripts stop too, fixedupdate and update stop being called the issue is not being stopped at the exact moment, you stop time.timescale

avatar image ccgtest · Jan 18, 2019 at 02:33 AM 0
Share

Simply talk about our game: There is only one player in the game, to collide with other gameObjects. For example: Palyer, cube_1, cube_2, cube_3, cube_4... cube_N. When the player click on the pause, I can stop the movement immediately with this script. But other gameObjects, like cube_1, cube_N, they are automatically moved by the physics engine, not by script. And we hope that they can stop accurately and immediately. Because this is a networked game based on frame synchronization. Do you have any suggestions? Thank you.

avatar image
0

Answer by xxmariofer · Jan 17, 2019 at 09:23 AM

There must be something else setting time.timescale to something else than 0, i was testing by changing FixedUpdate frequence in case it has to wait for the next update to change the time.scale value but even changing fixedupdate frequence to 1 or to 0.000001(ended up crashing) the time.scale stop was inmidiate, can you please log Time.timeScale value in the fixed update just for making sure is 0?

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 ccgtest · Jan 17, 2019 at 12:24 PM

Thank you for your help, but the problem is still not solved. This is new code. From the log, I think Time.timeScale value is 0 at runtime. But, FixedUpdate() can't stop immediately. We are make a physics game, and we hope to stop FixedUpdate() immediately. Sorry, my English is not fluent.

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System;
 
 
 public class Test_TimeScale_5 : MonoBehaviour
 {
     private int ph_frame = 0;
 
     void FixedUpdate()
     {
         ph_frame += 1;
         Time.timeScale = 0;
         Debug.Log("--FixedUpdate-- [ Time.timeScale=" + Time.timeScale.ToString()+ "], frame num: " + ph_frame.ToString());
     }
 }



qq截图20190117202244.jpg (13.1 kB)
Comment
Add comment · Show 1 · 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 xxmariofer · Jan 17, 2019 at 01:24 PM -1
Share

the easiest way of fixing it would be with an if statement at the beginning of the fixedupdate checking if time.timescale == 0; searching in the web i saw you can use Physics.Simulate for managing the physics yourself that might work.

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

103 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Pause game on Start doesn't quite work 1 Answer

Slow motion all but one - yet another round, hopefully the last 6 Answers

Physics calculations vs TimeScale vs FixedDeltaTime 1 Answer

How to use Time.fixedDeltaTime for slow motion? 1 Answer

Stopping FixedUpdate 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