- Home /
Any way to detect if a button is held down when the scene loads?
I am making a difficult Super Mario World like game where you have quick respawns when you die. However, if I hold the Run button when reloading the scene, it is not detected after the scene loads.
private void Awake() {
if(Input.GetButton("Sprint")){
Debug.Log("GetButton @ Awake()");
}
if(Input.GetButtonDown("Sprint")){
Debug.Log("GetButtonDown @ Awake()");
}
}
void Start()
{
if(Input.GetButton("Sprint")){
Debug.Log("GetButton @ Start()");
}
if(Input.GetButtonDown("Sprint")){
Debug.Log("GetButtonDown @ Start()");
}
}
None of this registers on scene load.
Any ideas?
Answer by badguy0325 · Dec 19, 2020 at 10:50 PM
I solved this by making a persistent input manager object separate from the player with DontDestroyOnLoad, then instead of checking Input.GetButton(), I check a bool that is set through GetButtonDown() and GetButtonUp() that persists through scene load on the input manager.
Your answer
![](https://koobas.hobune.stream/wayback/20220613021916im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I detect touch on another object and check by tag/name? 1 Answer
How can I make GUI button send an input message when I press it? 0 Answers
Input.getTouch() vs checking if button is clicked 1 Answer
My game breaks when I load it from another scene (menu scene). 0 Answers
WebGL Input Manager reacting 0 Answers