Author Topic: UIInput ignore typed space char and clear input value  (Read 1389 times)

DirtyHippy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 25
    • View Profile
UIInput ignore typed space char and clear input value
« on: August 28, 2014, 11:25:15 AM »
I'm trying to implement a behavior where you hit the space bar and depending on the tokens of the UIInput value, I ignore the space and clear the input value.

I have overridden ProcessEvent and picked up the space, and clear out the input, but the space gets added after the value is cleared (with return true or false - not sure what this return value does - I was hoping one of them would ignore the character).  This is very close to the behavior I want, but it adds the extra space at the beginning of the input.

I have tried to do the same in a validation callback, but the validation callback is in the middle of a string builder building the new value, so clearing the value in the callback doesn't have any effect.

I have tried some combinations of the two, but I wasn't able to get it to work.  I am assuming this is probably the approach I will need.

Any ideas?

Thanks!
Kirk

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput ignore typed space char and clear input value
« Reply #1 on: August 28, 2014, 09:21:02 PM »
Did you not look at the function you overwrote? It doesn't handle typing inside. It handles keys like Home, Backspace, Delete, etc. Actual input is done via Input.inputString in the Update() function.

If you want to ignore a character, input validation is the way to go.

If you want to clear the input when some character gets pressed, just Input.GetKey it in your script and set Input's text to nothing.