Unity editor setting Project Settings > Time > Time Scale to 0. Should it be doing that?

Hi!

I’ve had a good search around, but I can’t find any reference to this. Apologies if it’s a duplicate and has been raised already.

I’m finding, since upgrading to Unity 2021.3 LTS, that now and again something is changing my Project Settings, and effectively “freezing time”. It only seems to impact builds, but the result is that I trigger a build, go to test it, and find I get a black screen. Only way out is to kill the game process. The root cause is that somehow my Project Settings have been changed, and the Time > Time Scale setting has gone from “1” to “0”.

I’m not able to pinpoint exactly when this change happens, or how or why it’s made. It’s most definitely not me that’s changing the setting, it’s something in the background.

I wondered if this was “expected” in some scenario or if I should report this as a bug?

Many thanks for your thoughts!

That has to be some script (yours or part of a package) doing it, or else you are changing it through the editor.

If you use source control you may be able to pin down the antecedent activity that causes the change, because you will see a change to the TimeManager.asset file that you don’t want.

As a workaround, just set Time.timeScale = 1.0f; at the stat of each of your scenes (or even every frame in an Update() method)}, but most likely you will need to find what is setting your scale to zero.

I would agree 100% with Kurt. Something in your project is changing it. It may not be your own custom code doing it, but something is. GL.

Search your code for references to Time.timeScale

Thank you all kindly for the responses. This makes sense! I use Time.timeScale to pause the game. What I didn’t realise was that this directly modifies Project Settings every time it’s set in code.

So, if I happen to stop the game while it’s paused, then immediately exit the editor, when I reload or build, the setting is zero.

Has it always been the case that Time.timeScale is directly reflected in Project Settings like this?

I just tested in Unity v2021.3.10 and setting the Time.timeScale to 0 in the code does reflect it in the Project Settings during the Play. But as soon as I stop the Play it reverts to 1. Check your Enter Play Mode Settings, maybe that’s messing it?

I’ll check that, thank you!

What you describe, where the Time settings in Project Settings revert when coming out of run, does seem to bug out on me under certain conditions. Good to know at least what the expected behavior is. I’m honestly a bit surprised that setting the scale in code directly effects the project settings at all!

It’s kinda subtle: when you set it in code you are ONLY ever setting the one global notion of a “project setting…”

BUT! Unity saves those when you press PLAY and is supposed to restore them when you press STOP.

This allows you to set the scale through editor scripting and have it take permanent effect in the project. Most things in Unity work like this for this reason.

Great explanation, thank you! I’ve actually only just started discovering the benefits of Editor scripting, and it’s blowing my mind a little - in a good way, as it’s helping me automate a ton of stuff while removing a load of Start() and Awake() calls that I had been doing in runtime.

I’m going to keep an eye, now I’m on 2021.3.10, as there do seem to be occasions where the setting isn’t reverted on STOP. If I can pin that down, I’ll raise a bug.

Really grateful for your response, by the way. For some reason, I’d avoided raising stuff in the forums, but now that I am, I’m finding a very helpful community of experts who are willing to help newbies and hobbyists like me!

Because editor scripting runs in that twilight margin between the editor being at rest and playing your game, it can be a complicated beast.

It’s SUPER-powerful, but there’s a lot of wiggly moving parts, and it takes a lot of iterating and layers of understanding before you really can genuinely feel “Yeah, I know exactly what is going on here!”

Be patient. It all works and usually there’s a way to do almost anything.

Blowing your mind is one of the no-extra-cost side benefits of editor scripting, and Unity provides that for free. :slight_smile:

Welcome! We love seeing new people tackling Unity, and we love to see people grow and learn how to do amazing things. We do expect effort on your part, and your post above shows that effort. I always offer this template to help folks (old and new!) communicate their problems clearly:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

Sorry to bring up this old thread, but I’m having this issue with Unity 2023.2.17f1.

I am making some changes to Time.timescale during gameplay in Editor mode but this change not reverting itself only happens occasionally, I’m assuming its something to do with Github locking the file whilst in Play mode and then not getting reset when exiting play mode?

Thankfully, having the change show up in Github is a great way to realise why everything is suddenly broken but not intuitive to always check first. Is this a known issue or is there any work around?