Logic is CPU dependent and NOT Time dependent.

Hi All,

I just found something that concerns me, and thought I’d share it.

var secondsPerThing : float = 0.25;
var secondsPerThing : float = 5.00;

function Start() {
  InvokeRepeating("MakeThing", 0, secondsPerThing);
  Invoke("StopMakingThing", secondsOfThingProduction);
}

This logic is CPU dependent and NOT Time dependent as I had thought.

On my dev box…
Running In Unity Results: 24 Things
Running As a PPC Build: 22,20 Things (Fast,Hi-Qual)
Running In Web Player: 22 Things

If it were time dependent 5.00/.25 = 20 Things

So I tried offsetting by Time.deltaTime

var secondsPerThing : float = 0.25;
var secondsPerThing : float = 5.00;

function Start() {
  InvokeRepeating("MakeThing", Time.deltaTime, secondsPerThing);
  Invoke("StopMakingThing", secondsOfThingProduction);
}

On my dev box…
Running In Unity Results : 20 Things
Running As a PPC Build : 20, 18 Things (fast,hi-qual)
Running In Web Player : 15 Things

I can understand the number being >= 20, but I don’t understand why it would go <20.

SIDE NOTE:
var secondsPerThing : float = 0.25;
var secondsPerThing : float = 5.00;
- VS - 
var secondsPerThing : float = .25;
var secondsPerThing : float = 5;

alter the physics engine results;

fixed update is for time dependent code. it executes once per timestep.

Yes, FixedUpdated() executes every timestep.

InvokeRepeating() seems to be tightly in sync with the repeating time parameter. The part that makes it out of sync appears to be the starting parameter.

I wonder, does InvokeRepeating() not take the duration of the function call into account? That is, if you do InvokeRepeating(“Thing”, 0, 10), and Thing() takes two seconds to execute, does the next invocation happen at twelve seconds?

I haven’t tested this… just a thought.

Time.time is constant during the same frame.

sorry victom! i obviously didn’t read your post :sweat_smile: and don’t really have an answer for you. hopefully you’ve got it sussed.

makes sense that it would be <20 when offsetting by time.deltatime. don’t know what that value is returning but it’s some delay before your first instance. so now you’re stopping in less than 5 or rather secondsOfThingProduction - time.deltatime. time.deltatime is the time it took the last frame to complete making the script framerate dependent which explains the variance. over a full second does seem odd though. a lot going on in the scene? no errors? that’s a typo in the code you posted right (not copy pasted)? maybe what neil said? space/time continuum rift? what did joe mean? nm…

anyway in your first case, i agree that i’d expect invokerepeating to give consistent results based on time. weird.

a whacky idea… maybe using 0.0 as your offset? the param takes a float. maybe 0 is making something odd happen. wouldn’t expect so but who knows - I’ve had sillier stuff happen. your side note made me wonder…

I agree, it does appear to be ignoring the duration of MakeThing().
If I increase the inefficiency of MakeThing().
The code will produce more “things”.
Which implies (to me) that the Invoke for “StopMakingThing” is lagged by the amount of processing time of “MakeThing”.

I have to agree with pete on this. That’s too deep for me man. :wink:

  1. It would have to return a negative value (as I see it).
  2. No the scene is a simple test case.
  3. No typo’s (that I see) it was mostly C&P
  4. I’ll try the offset by 0.0 thing.
    ** Maybe Joe wants me to try Time.time instead of Time.DeltaTime?

Thanks for the replies (all).

  1. It would have to return a negative value (as I see it).

invokerepeating and invoke start at time zero. invoke waits 5 seconds. invokerepeating waits time.deltatime after invoke started waiting before MakeThing is called. that means Stop will be called in 5 - time.deltatime after the first instance of MakeThing. so MakeThing only runs for 5 - time.deltatime.

  1. No typo’s (that I see) it was mostly C&P

var secondsPerThing : float = 0.25;
var secondsPerThing : float = 5.00;

must be a forum typo. the second var is really secondsOfThingProduction in your script - right?

let us know if the 0.0 thing works out. i still say it’s a rift though… probably the one Joe came through! :smile:

[edit: don’t think time.time will work. that’s time the frame started since the start of the game. he meant it doesn’t change during a frame. just not sure how you’d use that or if it was in ref to neil’s q.]