Download

Key holding after next level is open

Hi,
I’m trying to create easy 2D game, where character can sprint through levels. Character will sprint when shift is held down. For some reason game can register holding D key for movement but can’t detect other key for sprint when character enters next level. Player has to press and hold sprint key again for sprint.

Is there any easy option how to register all held keys in next level without pressing them again?

One way you could achieve this is by saving all player held inputs in your GameInstance. For example, right before you load a new level, you could set bSprintButtonPressed = true/false. Depending on whether the button is pressed. Then when next level is loaded if it’s true, simulate as if sprint input is pressed, even though it’s not.

However I wonder if loading new levels is even necessary? If you want inputs to carry over it sounds like maybe it’s the same level. You could just teleport the camera to a new place and it would look like a completely new level to the player. Then you have no issues with inputs. But if you do the entire game like that, it might become a very bloated level. All depends on the game you’re making.