- Home /
How can I stop input while splash screen is displaying?
While the splash screen is displaying, input appears to be queueing up.
for example:
if (Input.GetKeyUp(KeyCode.Escape))
{
Application.Quit(); // <-- I have a Debug breakpoint here
}
If the user hits escape while the splash screen is displaying, the splash screen continues. However, after the splash screen is done, my breakpoint hits immediately.
I've tried this (before the above code):
if(!SplashScreen.isFinished)
{
return;
}
However, that doesn't resolve the issue. After the splash screen is finished, the Input.GetKeyUp(KeyCode.Escape)
returns true and my breakpoint still gets hit. I assumed perhaps that the input simply isn't processed till then so what I needed was essentially to skip the first frame and let the GetKeyUp call get reset.
I added the following below the SplashScreen.isFinished
call:
if(!IsInitialized)
{
IsInitialized = true;
return;
}
So the first time the Update call is run, it simply returns. That frame is essentially skipped from checking input. However, that doesn't work if the user has pressed multiple keys (or the same key multiple times) as it's just processed on the following frame, and the one after that, and the one after that...
The only way I've successfully gotten this to actually work is to change my IsInitialized check to:
if(!IsInitialized && !Input.GetKeyUp(KeyCode.Escape) && !Input.GetKeyUp(KeyCode.LeftArrow) && !Input.GetKeyUp(KeyCode.RightArrow) && ..) // <-- check every key my application uses
{
IsInitialized = true;
return;
}
// Future calls are properly handled as the game is actually playing and the queued input is effectively flushed
However, this feels like a terrible, terrible hack. Is there any other logical way around this? Is this a bug in the splash screen? Is there a way to flush the input events after the splash screen is done?
Just wanted to say a big thanks! I tried your last piece of code and that worked. Yes, it's hacky but at least it works so now I can finally move on to other things!
I think(untested) the issue can be resolved by allowing Input.Get$$anonymous$$eyUp() to be called while you splash screen is active- just take NO action. I would expect this to "eat-up" those events. edit: Nope. according to docs: "You need to call this function from the Update function, since the state gets reset each frame." though "reset each frame" certainly seems to be contradicted by your results.
That would make sense in theory but doesn't work in practice. If I understand Unity correctly and I think what's happening is that the Get$$anonymous$$eyUp
is all part of a messaging system. While the splash is playing the keyboard input is queued and my scene is loaded in the background. However, during this time my Update()
script isn't running. After the splash screen is loaded, my script starts running its update. However, the Get$$anonymous$$eyUp
messages accrued while the splash screen was playing so it's got n number of Get$$anonymous$$eyUps to burn through. It's not calls to Get$$anonymous$$eyUp
that burn through the events and they are ins$$anonymous$$d eaten up by frames.
Answer by McAden · Jul 21, 2017 at 08:14 PM
This has been repro'd and logged as a bug by the Unity team.