x


Why is InvokeRepeating going 1 second early if I set it to start in 0 ?

But if I set it to start in 0.0001, it works fine. What is going on here?

Here's the test script I noticed this happening in-

#pragma strict

var secs : float = 4.0;
var incTime: float = 0.0;
var fixedIncTime : float = 0.0;


function Start () 
{
Time.timeScale = 1.0;
InvokeRepeating ("SyncTime", 0, secs);
}

function Update () 
{
incTime += Time.deltaTime;
if (incTime > secs)
{
incTime -= secs;
}
}

function FixedUpdate () 
{
fixedIncTime += Time.fixedDeltaTime;
if (fixedIncTime > secs)
{
fixedIncTime -= secs;
}
}


function SyncTime ()
{
Debug.Log("Time is:"+Time.time);
Debug.Log("incTime: "+ incTime);
Debug.Log("fixedincTime: "+ fixedIncTime);
}
more ▼

asked Apr 29 '12 at 05:57 PM

Kiloblargh gravatar image

Kiloblargh
1k 33 54 70

Early? What does the output look like? Is time not showing roughly 0,4,8... ?

As for the incTimes, since they wrap around every 4, and you print every 4, the values should "randomly" be 0 or 4 (depending if it prints just barely before or just barely after each wrap-around.)

A delay of 0.0001 is really 1 frame, so it would make sure you print times just after each wrap-around.

Apr 29 '12 at 08:22 PM Owen Reynolds

Nope- try it- it's going 0, 3, 7, 11, 15 etc. The second time it invokes, it jumps the gun by one whole second, and remains 1 second behind what it should be, forever after that.

Apr 30 '12 at 01:01 AM Kiloblargh

No decimals? Debug will do some rounding. As a trick, you can print Time.time*100 to see more decimal points.

Apr 30 '12 at 01:42 AM Owen Reynolds
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x50
x1

asked: Apr 29 '12 at 05:57 PM

Seen: 395 times

Last Updated: Apr 30 '12 at 01:42 AM