- Home /
UI InputField does not consumer keyboard input
I have an input field which, when I type into it, also causes my character to move whenever I type in a movement key. For example, with each space in the input field, my avatar jumps.
I would think there would be a flag in the input field that says "consume these" and I'm hoping to find one because an update method that checks every tick and eats the character if the pointer is over the UI seems like a horrible waste of code and a huge hit in terms of unnecessary update cycles. Can't the UI do this for me? It should!!!
Is there something I don't know that will help with this or is the answer "suck it up and consume it yourself"?
Answer by steakpinball · Feb 02, 2015 at 07:04 PM
EventSystems.BaseEventData.used is the closest thing to what you're looking for. For each event this starts as false. When it is consumed by the UI it is set to true. Getting a reference to the event object and checking it will still require an update loop. A simpler solution would be to maintain the focus of the cursor.
void Update() {
if (gameHasFocus) {
// Process game world input
}
}
i.e. suck it up and consume it yourself
I really didn't get " Getting a reference to the event object", how can I get reference on Event Object ? For example I have Camera$$anonymous$$ovement script which uses "space" as reset position, when I press space in Input Field my Camera$$anonymous$$ovement script is also resetting camera position, how can I get Event Object in Camera$$anonymous$$ovement script ?
void Update() {
if (Input.Get$$anonymous$$eyDown("space")) {
//How Can I get Event Object here ?StartCoroutine(ResetPosition(resetSpeed));
return;
}
Your answer

Follow this Question
Related Questions
UI 4.6 input field how do I use the .onendedit? 1 Answer
Max Level reached ever 1 Answer
How to limit the number of line in an imputField? 0 Answers
Catching get focused for UI InputField 0 Answers