# Physics independent of the Framerate: using substepping but not working

**URL:** <https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782>\
**Category:** C++\
**Tags:** unreal-engine, question, CPP\
**Created:** [October 6, 2022, 5:59pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782 "2022-10-06T17:59:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wikiful](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wikiful](https://forums.unrealengine.com/u/Wikiful)\
**Post date:** [October 6, 2022, 5:59pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/1 "2022-10-06T17:59:31Z")

</div>

Hi everyone,

I got an question about how to make Physics computations independant of the framerate of the game.

I have one actor, a bouncing ball that have an impulse apply to it every tick to compensate the gravity. And when close to the ground, it receive a big impulse to make it “bounce”.

But the catch is that the final result will be very different depending of the framerate :  
 ![485116fa2d4edabb9f4577f895815fe1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/6/2c6a65cd27b8d707a15d1700dac9bfbc0449debb.gif) ![0c73427bfd997b36ea45e9995f6466f3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/e/46e0f455b61577dd3bda839edf09aeba8ffc3bf0.gif) ![943ee1216bfa0db3dc2e47b6674e6231](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/3/6338745ff49efe827ff2ef66cedaa849f8526c83.gif)

As we can see in these 3 gifs, in the first case with no restriction on the FPS, the ball is perfectly bouncing and slowly falling.  
In the second where I limit the max fps to 30, sometimes we only have half of a bounce. And for the third with a limit at 10, we only have small bounces and the ball could stay on the ground for a time.

On my side on the code, I looked at the Substepping physic system to have something that should be independent of the framerate. Here the snippets :  
[https://dev.epicgames.com/community/snippets/lNw/unreal-engine-physics-with-substepping-setup](https://dev.epicgames.com/community/snippets/lNw/unreal-engine-physics-with-substepping-setup)

( I know that there is also a way to register every ticks the substep’s method on the body instance of my StaticMesh, but this way from the BeginPlay seems more ideal and I didn’t see any differences. )

So, from that I would thought that every thing should have been identical no matter what the number of FPS were. I don’t think I forgot to enable something on the project settings either :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/3/f/13fabce51a526601adb6874894d4c53cc0738555.png)

Here are the source I had on the topic :  
[http://mansisaksson.com/view/ue4-substepping](http://mansisaksson.com/view/ue4-substepping)

> **[Framerate independent physics in UE4 · Víctor Ávila](https://avilapa.github.io/post/framerate-independent-physics-in-ue4/)**
>
> How to achieve physics framerate independence by correctly using UE4 substepping.

> [@How to make physics forces independent of frame rate?](https://forums.unrealengine.com/t/how-to-make-physics-forces-independent-of-frame-rate/294966):
>
> I’m trying to apply a physics force every frame to my object. I noticed that functions like AddImpulse and AddForce make the object move at different speeds depending on the frame rate. Multiplying the input by the delta time makes the object move faster the lower the frame rate. Not using delta time, as you would expect, makes the object move faster at higher frame rates. I tried using the Physics Thruster component but it has the exact same problem. Is there a way to apply physics forces every…

You will noticed that I don’t multiply the impulse with the delta time on the “counter gravity”. I don’t understand why but it seems that we don’t have to use the delta time in our physics tick computations.  
I have tried with both anyway, and it didn’t change anything.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/5/3451aa0558b43330972bd34a3d11cb0755791426.png)

So, does anyone with good physics knowledge could help me ?  
Thank you everyone =)

---

<div class="post-metadata">

**Author:** ![Wikiful](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wikiful](https://forums.unrealengine.com/u/Wikiful)\
**Post date:** [October 6, 2022, 6:25pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/2 "2022-10-06T18:25:53Z")

</div>

I made one discovery.

I displayed the DeltaTime that I have on the screen to see if it was indepedant of the framerate.  
When I set the limit to 30FPS, my DeltaTime is always 0.033333, and when sets to 10FPS it’s 0.1000. Which is exactly the inverse of the number of FPS, which proves that the substepping system is not working at all. And I don’t understand why =/

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 6, 2022, 6:28pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/3 "2022-10-06T18:28:58Z")

</div>

Delta time IS the frame rate 🙂

---

<div class="post-metadata">

**Author:** ![Wikiful](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wikiful](https://forums.unrealengine.com/u/Wikiful)\
**Post date:** [October 6, 2022, 6:32pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/4 "2022-10-06T18:32:56Z")

</div>

In the default Tick function yes, but still in the StepStepping one ? They don’t have their own delta time ?

How can I fix my code ?

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 6, 2022, 6:39pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/5 "2022-10-06T18:39:49Z")

</div>

Do you mean the tick node running in a blueprint with substepping enabled?

I thought substepping applied to the physics, but assumed that the tick node remained the same.

Sorry, I have no idea about how to fix the physics issue…

---

<div class="post-metadata">

**Author:** ![Wikiful](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wikiful](https://forums.unrealengine.com/u/Wikiful)\
**Post date:** [October 6, 2022, 6:49pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/7 "2022-10-06T18:49:51Z")

</div>

I code in c++ but it would be the same if I had made it available to BP.

Another tried that I made is to create a counter of substepping.  
In my Substepping tick I add +1 to my counter and on actor tick I display this counter and reset it.  
It always display 1 :  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/d/f/3dfd21c57564546cf182e161a3f8ddd338180f21.png)

And yes, I did enabled the smoothed framerate :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/4/5/a451327299d4d188cf0ba3a80e0fefe3447a584a.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 6, 2022, 6:57pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/8 "2022-10-06T18:57:09Z")

</div>

Yes, it is strange.

I assume you also followed the rest of that article, and worked with the ‘body instance’.

( I’m not checking, I actually assume you did ).

---

<div class="post-metadata">

**Author:** ![Wikiful](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wikiful](https://forums.unrealengine.com/u/Wikiful)\
**Post date:** [October 6, 2022, 6:58pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/9 "2022-10-06T18:58:11Z")

</div>

My source code is available here :

> **[Physics with Substepping setup | Unreal engine Code Snippet](https://dev.epicgames.com/community/snippets/lNw/unreal-engine-physics-with-substepping-setup)**

And thank you for taking time to help me ^^

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 6, 2022, 7:09pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/10 "2022-10-06T19:09:44Z")

</div>

Sorry, should have kept my virtual mouth shut 🤐

I just noticed your comment about tick and frame rate. And that’s exactly what you would expect.

I took a quick look at the code, but don’t see anything standing out.

---

<div class="post-metadata">

**Author:** ![Wikiful](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wikiful](https://forums.unrealengine.com/u/Wikiful)\
**Post date:** [October 8, 2022, 12:04pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/11 "2022-10-08T12:04:08Z")

</div>

Hello there !

I come back to my post to share a solution that I found.  
It seems that AddImpulse is not working with substepping, but AddForce is !

Looking at the declaration of the methods, it seems that only methods taking a bool bAllowSubstepping can be used that way (make sense).  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/4/5/f453ba7eebc4c85dfd66ddc6364df4174353d62d.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/1/1/111aa30fca4e7fc7f90ccec06e253a0951e3359c.png)

As I am already in an “Substep context”, I have to not allow Substepping when calling the methods, and it works.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/9/d/99d15761abe3e4cfa991bcd28f1a879f4ce30c9a.png)

Finally… my counter is still displaying only one substep by tick whatever the FPS limit I set… but it works so I’m not worry.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 8, 2022, 12:08pm UTC](https://forums.unrealengine.com/t/physics-independent-of-the-framerate-using-substepping-but-not-working/663782/12 "2022-10-08T12:08:36Z")

</div>

Excellent! 😅
