InputField bugs

Hi.
I am having trouble with InputFields on Android.
I have two InputFields. The problem is this:

Problem 1 (dublicated text):

  1. I press the “Username” InputField to give it focus and type some text.
  2. I press the “Password” InputField to give it focus. The text in the “Username” InputField now disappears (because there is nothing in the “Password” InputField).
  3. I type some text in the “Password” InputField.
  4. I press the “Username” InputField to give it focus. The text in the “Password” InputField is now the same as the “Username” InputField.

Problem 2 (text deletion, happens only sometimes):

  1. I press an InputField to give it focus and type some text.
  2. I press “OK”. Sometimes the text disappears.

I have reported a bug about this with a detailed description and a sample project: 689380

I really hope someone can take a look at this.

1 Like

I’m having the same problem since upgrading to Unity 5.0.1f1. I’d recommend falling back to 5.0 until it’s fixed. 5.0.1f1 pretty much ruined my app on Android. I haven’t tested other platforms yet.

EDIT - specifically, I’m experiencing problem #2 where text frequently disappears after being typed from the keyboard input and “OK” gets pressed.

Yeah, it is really frustrating that it doesn’t work.
I was actually on 4.6.3p2 when first encountering this problem, so I updated to 4.6.4p2 (from April 10th) to check if it was fixed, which was not the case.

I just hope someone at Unity sees this thread and/or the bug report.

I just now finished downgrading to 5.0.0f4 and deploying to my device and the problem #2 went away. So, for my part at least, it’s a 5.0.1f1 bug.

This also happens on Android 4.4.2.

I’m seeing the exact same thing. I’m tempted to grab the InputField sourcecode, to see if I can narrow down the problem! It lives here: https://bitbucket.org/Unity-Technologies/ui/src/fd5d3578da8c33883b7c56dd2b2f4d4bbc87095b/UnityEngine.UI/UI/Core/InputField.cs

1 Like

I’m having the same problem. hope they fix this problem soon

So, after some preliminary analysis of the InputField code, trying to specifically chase down giano574’s “Problem #2,” it looks like on my Kindle Fire, when the “Done” button is tapped, m_Keyboard (a TouchScreenKeyboard) briefly hiccups, and thinks its text value is empty. (Why, I have no idea.) That causes m_Text to get set to “”. Shortly after that, m_Keyboard reports that it’s no longer active, and this causes OnDeselect to be called. Ironically, by the time that happens, m_Keyboard knows what its text value is again! (Weird!)

I THINK I have a VERY TEMPORARY hack – er, I mean workaround for Problem #2 that you can use until the fine Unity folks fix this problem the right way.

First, grab InputField.cs from the link I provided above. You’ll probably also need SetPropertyUtility. (Alternatively, you can grab the entire UI source, if you’re feeling adventurous). I renamed my InputField, just to keep things clear. Now, go to the LateUpdate function, and somewhere around line 533, you’ll find this code:

            if (m_Keyboard == null || !m_Keyboard.active)
            {
                if (m_Keyboard != null && m_Keyboard.wasCanceled)
                    m_WasCanceled = true;

                OnDeselect(null);
                return;
            }

Change that to read:

            if (m_Keyboard == null || !m_Keyboard.active)
            {
                if (m_Keyboard != null && m_Keyboard.wasCanceled)
                {
                    m_WasCanceled = true;
                }

                // Silly hack to stop losing text when mobile keyboard is done.
                // See http://fogbugz.unity3d.com/default.asp?689380_uacuc6evpsvqj7at
                m_Text = m_Keyboard.text;
                SendOnValueChangedAndUpdateLabel();

                OnDeselect(null);
                return;
            }

In this instance, the keyboard code is not going through the validation system, but in theory, the text that is in there when this is happening should have already been validated.

I haven’t analyzed Problem #1 in any great depth yet, but there definitely seems to be some weirdness in the keyboard system.

Good news: I have a workaround for another problem.

In particular, if I have multiple inputs on the screen, and I go to edit one of them, all of the other ones get set to the original value of the one I am trying to edit. Very annoying!

TEMP WORKAROUND:

As above, you’ll need to hack up your own copy of InputField.cs.

Look for the line that says:

static protected TouchScreenKeyboard m_Keyboard;

Change it to:

protected TouchScreenKeyboard m_Keyboard;

I don’t know if there are any performance consequences to making this change, but working code is better than not-working code.

The source code I think someone mentioned is different between 4.6 and 5, also that site does not look updated for some time. Sorry for the offtopic.

The InputField code in the repo is less than two months old. That’s good enough for me, until they get it fixed up properly.

You are correct @MrEsquire , you can’t use the public UI source with U5 now, compatibility has been broken.
If you want to fix it in 5, you’ll have to copy the InputField code and make your own version of the control (with a different name, lol)

@Malkyne
That is amazing. How on earth did you figure that out?

For the problem where the field text was being wiped out, I put a whole lot of log messages in the InputField code, and patiently ran a bunch of tests, and studied the sequence of events. That one was a doozy.

For the other problem (where the text was being duplicated to other input fields), I already had a hunch. I searched for a static variable, and found what I was looking for immediately. The input fields are all sharing the same static mobile keyboard reference, so it is relatively easy to encounter a race condition that causes them to accidentally bleed text into each other.

Yes, precisely. As long as you rename it (and make sure that the AddComponent call doesn’t try to drop into a slot that conflicts with an existing component), it seems to work fine.

(Hopefully, they’ll get the UI repo caught up soon. I find it to be a very handy resource when I’m building my own custom components.)

Thank you very much. Hopefullly Unity will fix this soon though, so we don’t have to use temporary workarounds.

Well I hope for Fridays patch release.

But do they even know about these problems yet?
My bug report status is still “open”.

I don’t want to change all the input fields one per one, can I just replace the default script?

Edit: Ok, I did it. I had to download all and compile, generate a new dll and replace it.

Can someone from Unity confirm that you are aware of this problem?