I have a PlayerInput on a player prefab. I have a button that the player holds to run. That works fine when the button is pressed after the prefab is instantiated. But if the player is already holding the button when the prefab is instantiated, I receive no event calls. Which makes sense - they didn’t “just press” the button. But as far as I know, there’s no way to just check the Player Input control state, is there? Is the correct way to approach this problem to just avoid using the Player Input component? Or is there a way to solve it using that component?
The specific gameplay example: It’s a platformer game. The player is running around, falls into a lava pit. The level resets itself, deleting the old player instance and instantiating a new one. The player prefab has a Player Input component on it communicating with the player controller. If the player continues to hold the “run” button after dying, they are no longer running until they release and re-press the button.
Short answer: Switching the action type from “Button” to “Value” should do the trick.
Long answer: there’s an assumption built into this. Button behavior is expected to revolve around presses and releases whereas “value” behavior is taken you simply want the input to assume the current value of the control – whatever that is. So, unlike a button-type action, a value-type action will immediately go and check the current control value(s) when the action is enabled so that if a control is already actuated when the action is enabled, the action immediately triggers.
Thanks! That did the trick. I can see that the action is properly cancelled when the Player Input is destroyed, and re-performed when it gets reinstantiated.