Download

Best way to delay a running variable?

Hi There,

what might the best way be to delay a continuously changing variable?

I have some tracking data that updates 90 times per second and now say that I want to delay this by 25ms before using it? Ie I want to use the 25ms old value.
Must I store and manually reorder the older values in an array? Or is there a easier way to do this?

Cheers, Fred

Array and C++, You cannot do this in blueprints because you are not guaranteed to get 90 ticks per second.
Depending how accurate timing you need you may need to do some serious coding under windows.
Also if those values translate smoothly you may interpolate values when timing does not exactly fit.

Really hard to answer your problem without more info.

I think you can SET the variable and GET it every 25ms with something like this:

DO ONCE > SET VARIABLE (with the last refreshed value available) > DELAY(25ms - 0.025s) > GET VARIABLE > RESET the “DO ONCE” node

If you need a very accurate timing, try with a DELAY of 22/24ms but I think Gawrot show you the best way…

I doubt this will work. You willl need some kind of multithreading blueprints don’t support. But in case the OP already has that implemented (or he doesn’t need to store it exactly each 1/90 seconds because he knows what value the variable has to a given point in time), what’s easier than storing and reordering values in an array?

Thanks for all your advice!

Basically I want to store recent HMD/Motioncontroller tracking data so that in my multiplayer I can then use slightly older data.
To artificially introduce some lag compensation so that server player (listen server p2p) has less of an unfair advantage and so that Client play is closer to actual server play.
So it will be the local and not replicated data (I think).

I don’t think it has to be 100% accurate its probably ok with small time drifts I would guess.

Actually when I start looking at the numbers I’m realising that the array wouldn’t be that long at 90hz if I only want to go up to around 50ms max delay.
As that would be about a length 5 array. So pretty manageable.

I’ll just do some function with a loop in Blueprints to shift the value positions as new values come in. Always keeping the freshest value at [0].
Not too hard. Interpolation at use time might be nice though…I’ll think about that.

write a blueprint node for sleep that gets a float and runs this function : FPlatformProcess::Sleep( your time in seconds );
this function puts the thread to sleep. and it can be even gamethread. this way you can have even delayss in functions

here is a reference