- Home /
How to set up initial delay in UI key input repeat?
I'm making a menu with a set of options that the player navigates through using the keyboard or gamepad. If they hold down, the cursor highlight should cycle through all of the options.
Usually when you have a repeated input, there is a short delay after the initial input before it begins repeating - but Unity UI navigation does not seem to obey any settings from the OS.
I know you can make input repeat faster or slower using "Input Actions Per Second" on the "Standalone Input Module", but how do you implement an initial delay before input repeat?
Answer by applemaniac · Jun 15, 2015 at 07:09 AM
You can do this with a Coroutine and a boolean but it's not very clean.
if(///Your input here && canRepeat)
{
//Do what you want
canRepeat = false;
StartCoroutine(WaitAndRepeat());
}
...
...
IEnumerator WaitAndRepeat()
{
yield return new WaitForSeconds(waitTime);
canRepeat = true;
}
Thanks for the suggestion - I don't quite understand how this connects with UI navigation or the input module.
it's like a deboucing function. When you interact with your UI, you set a bool to false, and you build your UI to be interactable only if this bool is true.
In fact it's not clean at all :P YIELD generates lots of GC Allocations. But hey at least you got something for the guy unlike me :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613201013im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I disable gamepad input, for my UI? 1 Answer
How to make a true virtual keyboard for computer in Unity? 0 Answers
How do you make a method that gets called when a button gets highlighted using the arrow keys? 0 Answers
Only keyboard input works in mac build 1 Answer
UI Navigation with gamepad 7 Answers