how to run update while timescale = 0

Hi there,
I have a couroutine, which ran a while(). Everything worked, but when I popped it into my game, this coroutine is called while TimeScale is 0. Now, it does not function. Some google sources cited FixedUpdate and Update to not be affected by TimeScale however, I find differently.

So, how, can I run some type of update while timeScale = 0?

The scripting Reference of Unity says, that fixedUpdate is not being called when timeScale is 0 http://docs.unity3d.com/Documentation/ScriptReference/Time-timeScale.html. Are you running inside FixedUpdate? Do any Breakpoints get triggered, when you set them at the very beginning of classes (like Update)?

No, was perplexed for the longest time as my system ran fine, before I plugged it into game, but yes, once I plugged it in, and TImeScale was 0, the coroutine stops.

Currently I am running this, but I have kept timeScale at 1. This is unexceptable.

	void FixedUpdate(){
		if(!rtnToSnap)
		return;
		
		float speed = 100;
		float step = speed * Time.deltaTime;
		sphere.rotation = Quaternion.RotateTowards(sphere.rotation, sphereRtn, step);
	}

I’m certain that both coroutines and Update run while Time.timescale is 0.

Post your code.

thats it.

edit:

//////the end of the input release function... onTouchUp, OnMouseUp etc...........


			//Time.timeScale = 1;///with this out, it does not work.


			///begin sphere rtn into pos
			rtnToSnap = true;
		}	
	}
	
	void FixedUpdate(){
		if(!rtnToSnap)
		return;
		
		float speed = 100;
		float step = speed * Time.deltaTime;
		sphere.rotation = Quaternion.RotateTowards(sphere.rotation, sphereRtn, step);
	}

The same can be said for Update and any while() in a coroutine. If timeScale is 1, it works.

It’s already been said that FixedUpdate is not run when Time.timeScale is 0.

1 Like

I just did a double check and like I said, with Update or A coroutine while(), when TimeScale is 0, this does not work.

			///begin sphere rtn into pos
			rtnToSnap = true;
			StartCoroutine("snapSphereIntoPlace");
		}	
	}
	
	IEnumerator snapSphereIntoPlace(){
		while(rtnToSnap){
			while(rtnToSnap){
			float speed = 100;
			float step = speed * Time.deltaTime;
			sphere.rotation = Quaternion.RotateTowards(sphere.rotation, sphereRtn, step);
			yield return 0;
		}
	}
//////the end of the input release function... onTouchUp, OnMouseUp etc...........


			//Time.timeScale = 1;///with this out, it does not work.


			///begin sphere rtn into pos
			rtnToSnap = true;
		}	
	}
	
	void Update(){
		if(!rtnToSnap)
		return;
		
		float speed = 100;
		float step = speed * Time.deltaTime;
		sphere.rotation = Quaternion.RotateTowards(sphere.rotation, sphereRtn, step);
	}

It is still running but there is no change because you’re multiplying the step by the delta time (which is 0). You need to calculate the delta time yourself with Time.realtimeSinceStartup

3 Likes

Ah shoot box.
Thanks!