Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to get framerate independent / deterministic computations?

Is there a way to have framerate independent, deterministic computations?

With other words, is it possible to access the game world from a different thread, or, which would be ideal, having a function update on each physics substep?

The goal is to have an object update in reliable intervals, as opposed to having larger intervals when the framerate degrades. (See the comment to one of the answers.)

Product Version: Not Selected
more ▼

asked Oct 10 '14 at 09:19 PM in Using UE4

avatar image

1 3 4 7

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Why not use time based computations? Generally that is why delta-time is used for animation rather than each call of the tick. The same is applied to computations that need to be over time or over a set interval of time. Each call of the tick function supplies a parameter of "deltaTime" which is the number of milliseconds since the last tick. You can also get the delta time from the World Object.


(above code should work for most actors if you are not within a tick function.)

You should be able to use this for your interval based computations where 1000 milliseconds equating to 1 second.

more ▼

answered Oct 10 '14 at 10:40 PM

avatar image

449 32 25 55

avatar image BMN-01 Oct 10 '14 at 10:52 PM

This won't work well to react to the environment. Adjusting an object in velocity, position, and rotation to the ground it's hovering above requires a constant interval to remain deterministic.

avatar image ArcainOne Oct 10 '14 at 11:30 PM

Not really. I believe you are over thinking the problem here. If you have an object hovering above the ground and needs to stay a consistent distance between the ground, use a collision object. All you will need is a forward vector to determine where the object will be between the previous time interval and the new time interval. You can use the the collision object's hit normal to determine where the ground is and at what angle your hovering object should be at.

If you need to test for the object to collide with other objects during that time, perform a trace to determine if that object needs to adjust it's course during the current tick. Nav Mesh should help with navigating around complex terrain using AI. If this is a PC actor they it's their own fault if they hit that tree or rock.

Finally frame rates should be extremely fast, we are talking about 30-60 per second if not more on better machines, which honestly is faster than most conscious thought.

However I do not have the exact details on your problem and honestly cannot think for the life of me why, unless you are not using a capsule, sphere. or cylinder collier for automatic adjustments and ground collision tests, switching on a few settings within the Movement controller, or a decently implemented Nav Mesh, why you would need a set interval update not based on time.

Further more NOT using time based updates will result in different behavior faster or slower on other computers. This is why in game development as a whole we use time, and not computer ticks.

avatar image BMN-01 Oct 11 '14 at 10:31 PM

unless you are not using a capsule, sphere. or cylinder collier

I missed this line. Indeed I am not, I am adjusting via manual LineTrace distance checks.

avatar image BMN-01 Oct 11 '14 at 12:06 AM

Ah well. I may indeed overthink the problem. But let me say I have already created multiple prototypes, some updating each tick employing the delta time, one hooked to a timer with a fixed number of updates each second. The timer though only catches up on missed updates each frame so it comes down to the same result.

However, the issue is always the same. If, for example, moving towards a slope, and the update time is too long at high velocity, instead of rotating with the slope it crashes against it. I hope this illustration clears it up (pardon the quality, as I currently have no access to my drawing tablet): Illustration

As hopefully visible, it's important that the updates happen with just little time between them. My favorite solution would be having an iteration on each physics substep, instead of each game tick.

Another problem arises when calculating the force required to push the object away from the ground. If the update time is too long, it gets pushed further out than intended. Although if indeed there is no option to have a framerate independent calculation, I'll have to switch from functions of the likes of SetLinearVelocity to such as AddForce I reckon.

in.png (30.2 kB)
avatar image ArcainOne Oct 20 '14 at 07:09 PM

I can't help but wonder if a possible solution lies within the Vehicle template. In fact I'd put a lot of money on it. You'll most likely have to do some major overhaul to the system but considering how vehicles work I bet that is where you'll find your solution.

And when you do please post it, I am curious myself.

avatar image cgrebeld Oct 11 '14 at 01:06 AM

Have you tried the UPhysicsThruster component? I imagine you could make a pretty cool hovercraft with that and the proper collider.

(comments are locked)
10|2000 characters needed characters left

You could make your own sub-stepping simulation scheme using the DeltaTime.

This would do double-steps to keep your simulation intervals constant.

more ▼

answered Oct 10 '14 at 11:06 PM

avatar image

497 25 16 33

avatar image BMN-01 Oct 10 '14 at 11:32 PM

This would be theoretically the same as hooking to a Timer, wouldn't it? That wouldn't change that the time between some updates gets larger when the framerate drops. This could work if the objects transform is manipulated manually, but when accessing its physics (UE4 physics system) it's impractical.

avatar image cgrebeld Oct 10 '14 at 11:54 PM

Yes I was assuming you were doing your own simulation.

If that's not the case, I have to agree ArcainOne - you should try to use the physics system as it's intended. You can always turn on CCD in your bodies.

Also you can tune the PhysX fidelity with substepping options: https://www.unrealengine.com/blog/physics-sub-stepping

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

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

Answers to this question