Setting Time.timeScale to zero crashes Unity!?

I have a pause function in my game but every time i try to pause, unity freezes. I am not able to unpause or even close Unity without using the task manager.

	if (Pause==false)
		Time.timeScale=1;
	else
		Time.timeScale=0;

I have used Time.timeScale on earlier games without this problem.
Any ideas to what the problem might be?
Thx.

try to set to 0.0001 or similar

there is a pause script at unity wiki

That is highly suspicious, I’ve used it many times as well.

Sounds like en endless loop or a divide by 0. Is it possible you have some logic elsewhere that would crap itself if Time.deltaTime were 0 or something?

That piece of code is the only code adressing time so i cant possibly see how anything else should mess with it.

uggh, that sounds like a pain to debug. Maybe you are hitting an infinite loop somewhere. Do you have any loops where Time.deltaTime is being used to increment the loop or set up a counter? Or some other place where a deltaTIme of 0 would cause problems?

That is also what i am doing until i find a solution but i makes no sense that im not able to use a simple Time.timeScale=0 code…

Nope. As i said before, this is the only place i even use time… Time is not really my strong side and i actually still strugle with the use of Time.deltaTime :confused:

Assuming you don’t have access to the debugger, you best bet to figure out what is happening is to disable scripts to find out which one is breaking. If your really have no clue which one is breaking you’ll have to go with the classic, painful binary search technique:
Disable half your scripts and see if it still breaks. If it does, it’s probably in the enabled scripts. Split those in half, etc. Not fun.

But i cant possibly see what script i should be… of all the scripts in the game, i am pretty sure none deals with time in any way, exept from these four lines.

I had a similar problem.
I was able to set it to 0, but then I couldn’t set it back to 1, because it kept crashing somewhere.

I fixed it by setting Time.timeScale = 0.0001;
for some reason it doesn’t like 0 …

I had the same problem and it turned out to be the cloth physics component, as soon as I deleted it the problem went away. Maybe you got the same issue or some other rigidbody related problem:)