Is there an equivalent to FixedUpdate that works when time.timescale = 0?
I have a function that currently executes in Update, which means it sometimes goes quicker/slower depending on framerate. I need it to happen at a fixed rate. The obvious solution would be to execute the function in FixedUpdate, but at the time the function occurs, time.timescale is set to 0.
(I have tried googling this but I can only find threads where people are asking the opposite question (how can I make things stop happening when time.timescale = 0))
FixedUpdate is not what you should be using. If its a fixed real world clock you need to execute against then…
Either update(), with a float time Elapsed += time.deltatime and check when your time elapsed exceeds the desired execution rate, or a coroutine with yield waitforseconds.
void Update()
{
if (finished == true)
{
scoreAppearsTimer += Time.fixedDeltaTime;
if (scoreAppearsTimer > 0.5f && scoreAppearsTimer < 0.51f)
{
totalTimerGO.gameObject.SetActive(true);
}
if (scoreAppearsTimer > 0.75f)
{
plus1.gameObject.SetActive(true);
}
if (scoreAppearsTimer > 1)
{
totalDiceGO.gameObject.SetActive(true);
}
if (scoreAppearsTimer > 1.25f)
{
plus2.gameObject.SetActive(true);
}
if (scoreAppearsTimer > 1.5f)
{
totalDeathGO.gameObject.SetActive(true);
}
if (scoreAppearsTimer > 2.5f)
{
finalScoreGO.gameObject.SetActive(true);
}
if (scoreAppearsTimer > 3f)
{
scoreAppearsTimer = 3;
}
}
}
To clarify, should that be working at a constant rate (against a real world clock, as you state)? If so, then I guess my problem lies elsewhere (as I’m trying to get multiple things to sync up on different scripts against a 3 second timer)
As per the original question, time.timescale is set to zero when this function occurs, so Time.deltaTime is not moving the timer. Time.fixedDeltaTime doesn’t seem to be syncing with actual seconds either. Should it be?
if (scoreAppearsTimer > 0.5f && scoreAppearsTimer < 0.51f)
{
There is no guarantee Update() will execute during this period.
It looks like your animating a process, I would instead increment a frame counter at a fixed time as you are doing and record the last executed frame , and execute from that frame to current expected frame based on elapsed time. That ensures any latency in the process will not result in parts being skipped.
Also since this thread is a lot to do with timing and whatnot, let me offer you this awesome graphic from the Unity docs, which can help you stick it all into the proper places in your brain: