- Home /
My game have FPS drops when Input.GetKey is triggered
Hi there. My game drops from 400fps to 260fps when I press any inputs I set in my script. Notice that even having the player static (as in, he's not moving when I press an input. Only calculations happen) the FPS drop is still here.
Here's some code:
void Input(){
if (isGrounded && fullControl)
{
inputDir = Vector2.Lerp(inputDir, Vector2.zero, recoverSpeedRate * TimeConstant);
}
if (isGrounded)
{
//Basic input
if (Input.GetKey(KeyCode.W))
{
inputDir.y = 1;
}
if (Input.GetKey(KeyCode.S))
{
inputDir.y = -1;
}
if (Input.GetKey(KeyCode.A))
{
inputDir.x = -1;
}
if (Input.GetKey(KeyCode.D))
{
inputDir.x = 1;
}
}
void SpeedManager()
{
//Sprinting
if (isSprint)
speed = SpeedInterpolation(sprintSpeed, recoverSpeedRate);
//Crouching
else if (isCrouched)
speed = SpeedInterpolation(auxMoveSpeed / 2, recoverSpeedRate);
//Sliding
else if (isSlide)
{
fullControl = false;
if (terrainSlope > 10f)
speed = SpeedInterpolation(speed + Mathf.Abs(transform.position.y), 0.5f);
else
speed = SpeedInterpolation(auxMoveSpeed, 1f);
}
else if (isGrounded)
{
speed = SpeedInterpolation(auxMoveSpeed, recoverSpeedRate);
fullControl = true;
}
}
float SpeedInterpolation(float finalSpeed, float _time)
{
float speedInterpolation = Mathf.Lerp(speed, finalSpeed, _time * TimeConstant);
return speedInterpolation;
}
Hope you can at least help me brainstorm. Any help is appreciated :)
Answer by hilljoh6 · Jan 15, 2021 at 06:17 PM
Hi there @Suave ,
I'm just starting to use Unity, but I ran into a similar problem as you described with GetKey. What worked for me was to close Evga Precision XOC program. I saw this suggestion in another thread, and when I exited Precision the FPS drops disappeared. Don't ask me why, but it worked.
Of course, if you don't have Precision, then I'm afraid I can't help you :).
Good luck!
Answer by andrew-lukasik · Jan 15, 2021 at 07:36 PM
"Drop" from 400 fps to 260 fps is not a framerate drop, it's a measurement error. What's more, no gaming system known in 2021 needs more than 90 fps. All framerate > 90fps is just inefficient home heating.
What you describe represents CPU time increase from 2,5 ms to 3,8 ms. And while whopping 1 ms is, yes, a lot of sweet CPU time indeed - this probably represents no properly isolated measurement. Because at fps range this high 1ms might be anything really - and you need to look into Profiler window to know something about that.
Your answer
![](https://koobas.hobune.stream/wayback/20220612232939im_/https://answers.unity.com/themes/thub/images/avi.jpg)