- Home /
How to set updates per second for testing purposes?
I have a difficult testing problem. I've determined that on someone else's computer, the PC version of my game executes update() on game objects much more frequently than on my machine. This broke my game badly, and I was only able to fix it by GUESSING at fixes and then asking my friend to confirm whether the fixes worked. I want to look for other issues like this, using my own machine. Can I somehow tell the Unity editor to change the number of game frames per second when it runs, for my testing purposes?
Answer by Bunny83 · Nov 24, 2017 at 04:46 AM
No, not really. There is the targetFrameRate setting but you can't really rely on it. If the hardware can't reach the desired framerate it would run slower. Also, as you can read on that page, depending on the target platform the setting might not have any effect at all.
The general solution to this problem is to make all your calculations framerate independet and make it time dependent. This is done by using Time.deltaTime as a factor in your calculations. For example when you want to move 5 world units per second you just add "5" multiplied by Time.deltaTime. This results in a fractional movement amount that will cause the object to move 5 units after one second.
Time.deltaTime is the time between the last frame and the current. 1f / Time.deltaTime
will return the actual framerate. So at a framerate of about 60 fps deltaTime will be 1f / 60 == 0.01666. At 100 frames per second it will be 1f/100 == 0.01 and at 25 fps it will be 1f/25 == 0.04
It should be obvious if you have a frame rate of 25 frames per second and you add "0.04" every frame that it will be add up to "1" after 25 frames or one second.
Thanks for the info on targetFrameRate. It's disappointing that it can't be relied upon - it's critical to be able to simulate performance differences across devices, especially considering how many platforms Unity can deploy to. I think it's unrealistic for an indie developer to own several different devices with differing performance profiles per target platform.
Your answer
![](https://koobas.hobune.stream/wayback/20220612143244im_/https://answers.unity.com/themes/thub/images/avi.jpg)