Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

InputField bugs

Discussion in 'UGUI & TextMesh Pro' started by giano574, Apr 14, 2015.

  1. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    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.
     
    ChallengerCC likes this.
  2. jmcclure

    jmcclure

    Joined:
    May 5, 2009
    Posts:
    48
    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.
     
    Last edited: Apr 14, 2015
  3. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    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.
     
  4. jmcclure

    jmcclure

    Joined:
    May 5, 2009
    Posts:
    48
    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.
     
  5. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    This also happens on Android 4.4.2.
     
  6. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    MrEsquire likes this.
  7. dungmv

    dungmv

    Joined:
    Apr 9, 2015
    Posts:
    5
    I'm having the same problem. hope they fix this problem soon
     
  8. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    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:

    Code (CSharp):
    1.  
    2.             if (m_Keyboard == null || !m_Keyboard.active)
    3.             {
    4.                 if (m_Keyboard != null && m_Keyboard.wasCanceled)
    5.                     m_WasCanceled = true;
    6.  
    7.                 OnDeselect(null);
    8.                 return;
    9.             }
    Change that to read:

    Code (CSharp):
    1.  
    2.             if (m_Keyboard == null || !m_Keyboard.active)
    3.             {
    4.                 if (m_Keyboard != null && m_Keyboard.wasCanceled)
    5.                 {
    6.                     m_WasCanceled = true;
    7.                 }
    8.  
    9.                 // Silly hack to stop losing text when mobile keyboard is done.
    10.                 // See http://fogbugz.unity3d.com/default.asp?689380_uacuc6evpsvqj7at
    11.                 m_Text = m_Keyboard.text;
    12.                 SendOnValueChangedAndUpdateLabel();
    13.  
    14.                 OnDeselect(null);
    15.                 return;
    16.             }
    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.
     
  9. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    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:
    Code (CSharp):
    1. static protected TouchScreenKeyboard m_Keyboard;
    Change it to:
    Code (CSharp):
    1. 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.
     
  10. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
  11. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    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.
     
  12. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,648
    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)
     
  13. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    @Malkyne
    That is amazing. How on earth did you figure that out?
     
  14. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    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.
     
  15. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    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.)
     
  16. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    Thank you very much. Hopefullly Unity will fix this soon though, so we don't have to use temporary workarounds.
     
  17. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Well I hope for Fridays patch release.
     
  18. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    But do they even know about these problems yet?
    My bug report status is still "open".
     
  19. ShabihDesperado

    ShabihDesperado

    Joined:
    Oct 27, 2013
    Posts:
    41
    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.
     
    Last edited: Apr 17, 2015
  20. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    Can someone from Unity confirm that you are aware of this problem?
     
  21. BakuDigital

    BakuDigital

    Joined:
    May 9, 2013
    Posts:
    18
    Same problem here, many conflicts with multiple uses of Input fields on Android devices (not tested yet on other platforms). Text sometimes disappears, duplicates partially on others Input fields... Very annoying.

    Hope there will be an official fix soon, on Unity 4 as well. Thank you !


    And by the way, thanks Malkyne for the workaround. I haven't tested it yet, but i hope it'll do the trick ! ;)
     
  22. AndersonRubio

    AndersonRubio

    Joined:
    Mar 10, 2014
    Posts:
    3
    My game uses a lot of Input Fields, and in this moment doesn't work. My current Unity version is 5.0.1f1. The Problem 2 (text deletion, happens only sometimes) occurs on my 3 Android devices of Test.

    So I'll downgrade to Unity 5.0.0f4, but now the scenes not open and the Hierarchy view is empty :(
     
  23. AndersonRubio

    AndersonRubio

    Joined:
    Mar 10, 2014
    Posts:
    3
    Malkyne likes this.
  24. cavev

    cavev

    Joined:
    Dec 5, 2014
    Posts:
    1
    I have tested Patch 5.0.1p1, the same problem appeared on android. How do I ? amazing!
     
  25. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    I spent a bit of time testing this patch on my Android device. Here are my findings:

    Problem #1 (Duplication of values to other input fields):

    NOT FIXED

    Problem #2 (Value disappearing on enter):

    FIXED

    So, if you have a screen with just one input on it, this patch will probably fix your problems. If you have multiple inputs, you will probably need to continue using the workaround.
     
    MrEsquire likes this.
  26. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    I have had the same experience as you. I hope Unity will realize this soon.
     
  27. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    I agree with your findings. We have wasted SO much time fooling with the broken InputField.

    Question: If I create a custom InputField, how do I get it in the Unity /UI menu? I'm totally stumped.

    Thank you!

    Karl
     
  28. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38

    I agree with your findings. We have wasted SO much time fooling with the broken InputField.

    Question: If I create a custom InputField, how do I get it in the Unity /UI menu? I'm totally stumped.

    Thank you!

    Karl
     
  29. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,648
  30. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    Thank you for a very fast reply.

    I didn't understand that you have to build up the UI. Got it.

    Much appreciated!

    Karl
     
  31. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    SimonDarksideJ and KarlShifflett like this.
  32. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    Malkyne,

    Thank you. I'll get on this. I've also fixed other bugs as well.

    Karl
     
  33. Undertaker-Infinity

    Undertaker-Infinity

    Joined:
    May 2, 2014
    Posts:
    103
    You guys saved me so hard. I had the duplicate input bug and the disappearing input text bug.
    I went back to 5.0.0 and the disappearing input text bug went away. I worked around the other and my all-form proyect works properly now. Thanks.
    I hit the duplicate input bug in a rather funny way: I had a component on it setting the text on that field based on the input from another field, listening to changes on it. When it set the text on itself, it would also set it on the field it was listening too, which would trigger another event....... and infinite loop of fields flipping out.
    I just don't update now and the app is uglier for it, so I figured I'd just mention it here.

    This is the code:

    Code (CSharp):
    1.  
    2. public InputField RUTInputField;
    3.  
    4.     void Start () {
    5.         RUTInputField.onValueChange.AddListener((value) => setVerificadorFrom(value));
    6.     }
    7.  
    8.     public void setVerificadorFrom(string numberString){
    9.         InputField inputField = transform.GetComponent<InputField> ();
    10.         inputField.text = CalcularDigitoVerificador (numberString);
    11.     }
    12.  
     
  34. MochiBits

    MochiBits

    Joined:
    Mar 11, 2014
    Posts:
    26
    I was able to get this bug to happen when Best Fit = ON. The bug didn't happen with Best Fit = OFF.

    Let me know if you try it out. Curious to know why it's even doing that.
     
  35. Undertaker-Infinity

    Undertaker-Infinity

    Joined:
    May 2, 2014
    Posts:
    103
    I had Best Fit set to OFF
    Disappearing text bug happens in 5.0.1, not in 5.0.0
    Duplicate input bug happens in both
     
    ajmarini likes this.
  36. ajmarini

    ajmarini

    Joined:
    Mar 13, 2015
    Posts:
    5
    Is there a solution for this yet? I am having inputs disappear on confirmation on seemingly random occasions.
     
  37. ShabihDesperado

    ShabihDesperado

    Joined:
    Oct 27, 2013
    Posts:
    41
    The solution of @Malkyne works for me. I recompiled the dll and I have the game on the stores.
     
  38. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,026
    Anybody else have the caret get stuck after you disable the game object or the parent game object?
     
  39. ajmarini

    ajmarini

    Joined:
    Mar 13, 2015
    Posts:
    5
    Oddly enough, mine was fixed by just deleting the placeholder texts. I've only been testing for few hours but the problems I had seem to be gone.

    Update - ya, nevermind. That didn't fix it. I will look into Malkyne fix
     
    Last edited: May 13, 2015
  40. WarrenB

    WarrenB

    Joined:
    May 24, 2012
    Posts:
    21
    I've been beating my head against the wall with this. I see the blank field problem is supposedly fixed, but my tests are still showing the bug on my device. Anyway, I made a temporary solution/hack because I need this to work today.

    Hopefully someone else finds it useful. Attach this MonoBehaviour to your input field and it should work. I'm using the onEndEdit event with my field so I wired that up to work as well. Please share if you make improvements. I can't wait for this to be officially fixed.


    //This is gross, but seems to work.

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class InputBugFixer : MonoBehaviour {


    string myCopy;
    bool locked = false;
    private InputField inputField;


    // Use this for initialization
    void Start () {
    #if UNITY_ANDROID
    inputField = gameObject.GetComponent<InputField>();

    UnityEngine.Events.UnityAction<string> changeCall = new UnityEngine.Events.UnityAction<string>(onChangeValue);
    InputField.OnChangeEvent valueChangeEvent = inputField.onValueChange;
    valueChangeEvent.AddListener(changeCall);

    InputField.SubmitEvent submitEvent = inputField.onEndEdit;
    submitEvent.AddListener(this.onSubmit);
    #else
    Destroy(this);
    #endif
    }



    public void onChangeValue(string value){
    StartCoroutine(setValueDelayed(value));
    }

    private IEnumerator setValueDelayed(string value){
    yield return new WaitForSeconds(0.5f); //give the script time to submit the correct value before changing data
    myCopy = value+"";
    }



    private IEnumerator triggerEventDelayed(string value){
    yield return new WaitForSeconds(0.5f); //wait for possible race conditions to settle down?
    InputField.SubmitEvent submitEvent = inputField.onEndEdit;
    submitEvent.Invoke(value);
    inputField.text = value;
    }



    public void onSubmit(string value){
    if(locked){
    locked = false;
    return;
    }

    locked = true;
    StartCoroutine(triggerEventDelayed(myCopy+""));
    }

    }
     
  41. ajmarini

    ajmarini

    Joined:
    Mar 13, 2015
    Posts:
    5
    I updated to 5.0.1p4 and that seemed to fix it. Updating to 5.0.2f1 now.
     
  42. Bobszee

    Bobszee

    Joined:
    Apr 4, 2014
    Posts:
    2
    Hi Guys!

    I have the same bug, EndEdit not saved my data, so i want use Malkyne's solution. How can i do exactly?
    1. Creat a c# script, copy the linked content there. But now i have an error "SetPropertyUtility not exist".

    I am not find the retail InputField.cs, how can i raplace it?

    I used the latest "Unity 5.0.2p1 (64-bit)" version.

    My English not the best, but i cant't find solution.

    Thx!



    WarrenB, your method working fine, Big Thanx!.
     
    Last edited: May 16, 2015
    WarrenB likes this.
  43. wiggums

    wiggums

    Joined:
    Oct 20, 2012
    Posts:
    31
    I've tried copying this and using your solution but I'm getting all sorts of errors like "SetPropertUitility does not exist".just like the guy above me. Seems like this bug has been here forever...

    Any help anyone?
     
  44. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
  45. Malkyne

    Malkyne

    Joined:
    Nov 18, 2009
    Posts:
    37
    I'll add: The reason you need to add your own version is because the official Unity version is declared as internal. That means it's only available within the UI package, and not to anything outside of it.

    You will probably also want to change the namespace on your own copy of SetPropertyUtility, since your version isn't really in the UnityEngine.UI package. Be sure that whatever namespace you give it is accessible from your version of InputField.

    Let me know if you need any other clarification.
     
    ChallengerCC likes this.
  46. wiggums

    wiggums

    Joined:
    Oct 20, 2012
    Posts:
    31
    Last edited: Jun 1, 2015
  47. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    How do you use the modified InputField in a Unity Project?
    I have tried editing the InputField.cs, building the solution and copying the contents of the Output folder into Data\UnityExtensions\Unity\GUISystem\

    However, I get two errors. One when opening the project (I get 18 identical errors)
    MissingFieldException: Field 'UnityEngine.TextGenerationSettings.scaleFactor' not found.
    UnityEngine.UI.Text.OnFillVBO (System.Collections.Generic.List`1 vbo)
    UnityEngine.UI.Graphic.UpdateGeometry ()
    UnityEngine.UI.Text.UpdateGeometry ()
    UnityEngine.UI.Graphic.Rebuild (CanvasUpdate update)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate ()
    UnityEngine.Canvas:SendWillRenderCanvases()
    The other happens after pressing play:
    MissingMethodException: Method not found: 'UnityEngine.Input.get_mouseScrollDelta'.
    UnityEngine.EventSystems.StandaloneInputModule.ProcessMouseEvent ()
    UnityEngine.EventSystems.StandaloneInputModule.Process ()
    UnityEngine.EventSystems.EventSystem.Update ()

    I am on Unity 5.0.2f1 right now.
    Can someone tell me what I am doing wrong?
     
  48. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    Anyone?
     
  49. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    do you skype?
     
  50. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    I have Skype, but no microphone if that's what you mean.
     
unityunity