Search Unity

InputField.text Not Showing Value

Discussion in 'UGUI & TextMesh Pro' started by Hotshot10101, Nov 7, 2014.

  1. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Before I submit a bug I wanted to see if there was something I was doing wrong with the upgrade. I have a project I have been working in 4.6b20. I just upgraded to 4.6f1.

    I have several InputFields in the project and the compiler told me all of them didn't have .value anymore. This I knew from reading the release notes. I changed all of them to .text.

    I have code similar to the following:

    if (Email != null && settings.User.Email != null)
    Email.text = settings.User.Email;

    Where Email is an InputField that I am trying to initialize with my saved email address.

    When I do this nothing shows up in the input field at run time. Is there something else I need to change or is there a different way to initialize an input field with a value at runtime? Using .value worked in the previous beta.
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    We're not aware of this issue. Please file a bug report with minimal repro case and post the case number here so we can look at it as soon as possible. Thanks!
     
  3. paradizIsCool

    paradizIsCool

    Joined:
    Jul 10, 2014
    Posts:
    178
    Same for us, from b20 to rc1 too
     
  4. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I was able to create a very simple project that shows this happening. Instructions to repro are in the bug report.

    The bug id is: 646147
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Thanks, that's a good repro project!

    We've verified the bug and we'll look into it first thing next week.

    A workaround that might work for now to force the InputField text to get updated is to disable and enable the InputField component.
     
  6. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    The work around does work. I will implement it as a static helper method so I don't have to refactor all my code again right away after the fix.

    Any idea when this will be in a fixed version?
     
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    i *THINK* we are trying for the next RC but I might be wrong so please dont hold me to it :)
     
  8. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Awesome!
     
  9. vatara

    vatara

    Joined:
    Feb 26, 2010
    Posts:
    22
    I have the same problem, but have noticed this fix does not work if the InputField is a LayoutElement. I haven't found any workaround for this yet, other than to check "Ignore Layout".
     
  10. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Whoops, just submitted a duplicate bug report for this. Definitely an issue.
     
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Can you report a bug with minimal repro project that shows this problem? We want to make sure the real fix will work for layout elements too. Post the case number here so we can fast track the issue. Thanks!
     
  12. vatara

    vatara

    Joined:
    Feb 26, 2010
    Posts:
    22
    Sure, it's case #646375
     
  13. diginikkari

    diginikkari

    Joined:
    Sep 3, 2014
    Posts:
    8
    Is this post to be fixed in RC2? I have still this same problem. I have to disable and enable inputfield component, before text is visible.
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Should have been in RC2, do you have your input field under a layout component.?
     
  15. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I just downloaded the new RC2 and this is fixed! I have not tried it inside of a Layout Component.

    You guys are AWESOME!!!
     
  16. diginikkari

    diginikkari

    Joined:
    Sep 3, 2014
    Posts:
    8
    Phil, yep, when inputfield is under layout group, bug is still there. Timing also has part of it. If I set the text in Start() -method, text is visible, but if I set it in Awake (), text is not visible. In my actual project I'm not setting text from Awake, put I'm setting it from another script which is loaded earlier.

    I made a very simple project to reproduce it (attached). There is only canvas and one inputfield under it. Canvas have horizontal layout group component. Inputfield has script with following code:

    Code (csharp):
    1.  
    2. void Awake () {
    3.     GetComponent<InputField>().text = "TextFromScript";
    4.     GetComponent<InputField>().textComponent.text = "TextFromScript";
    5. }
     

    Attached Files:

  17. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    under a layout group we noticed the bug after RC2 was out. I'm not sure if we are patching it into RC3 but we do have it fixed.
     
  18. diginikkari

    diginikkari

    Joined:
    Sep 3, 2014
    Posts:
    8
    Good know that it is fixed, hopefully the fix will be in RC3. Unfortunately I haven't figured out any workaround when there is layout used.
     
  19. diginikkari

    diginikkari

    Joined:
    Sep 3, 2014
    Posts:
    8
    Fix was not included in RC3 :-( will it be in RC4?

    Does anyone have any workaround how to get text visible when inputfield.text is updated from script and inputfield is part of layout group?
     
  20. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    This fix didn't make it for 4.6.0 but it's been fixed in our codebase already and will be in one of the patch releases following shortly after 4.6 is released.
     
  21. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    @runevision, does your last post suggest that RC3 is final RC before public release?
     
  22. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    i think thats the current thought but things can change at any time.
     
  23. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    No, that can't be inferred. :) In the RC phase we don't just include every fix we make, because every fix has a risk of regressions too. So we only include the most critical fixes. For that reason, we can say here that we know some fix isn't going to make it for 4.6.0 even though there still might be more RCs coming - they just won't include the fix.

    By definition, every RC is supposed to be the last one, unless something unexpected comes up. That's what Release Candidate means.
     
    rakkarage likes this.
  24. Raimis

    Raimis

    Joined:
    Aug 27, 2014
    Posts:
    160
    Thanks for your answer. Well I know the definition of RC, but given there were few rather random bugs reported (including this one), the post seemed rather strange to me, hence wanted to clarify :) Thanks for the answer.
     
  25. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I would suspect the reason they did not include this (if they didn't) would be that there is an easy work around. I guess easy is relative. All you have to do is what I did originally because i wasn't sure when the fix would be available.

    I wrote a static helper function like this:

    public class HelperScript
    {
    public static void SetInputField (InputField inputField, string text)
    {
    if (inputField != null && text != null)
    {
    inputField.text = text;
    inputField.enabled = false;
    inputField.enabled = true;
    }
    }
    }

    I then replaced all the places where I need to set an InputField to call this method instead. Then once the fix is in place I can just comment out the inputField.enabled = false / true.

    Then if I really want to later I can go back and fix all the places, but I would never need to do that if I don't have to.

    I am not trying to discount how big of a bug this is, but reality is what it is.
     
  26. diginikkari

    diginikkari

    Joined:
    Sep 3, 2014
    Posts:
    8
    Thanks Hotshot10101 for sharing. It gave me idea for my script. My current problem was that I was able to get the inputfield visible also in layout group by setting both text and textcomponent.text (setting enabled to false and true didn't work with layout group), but when I clicked input field it turned empty. I was able to do workaround to this by following helper script.

    Order of MoveTextEnd and textComponent.text was important.

    Code (csharp):
    1.  
    2. usingUnityEngine.UI;
    3.  
    4. publicclassHelperScript
    5. {
    6. publicstaticvoidSetInputField (InputFieldinputField, stringtext)
    7.  {
    8. if (inputField != null && text != null)
    9.  {
    10. inputField.text = text;
    11. inputField.MoveTextEnd(true);
    12. inputField.textComponent.text = text;
    13.  }
    14.  }
    15. }
    16.  
     
  27. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Glad to help and thank you for sharing your stuff as well.
     
  28. millwardesque

    millwardesque

    Joined:
    Sep 20, 2014
    Posts:
    1
    What's the max amount of time I can necro a thread? ;)

    This issue is still happening occurring for me in 5.0 when I try to set the text property of an InputField component that's attached to a GO with a LayoutElement component as well.

    I haven't had any luck with the solutions posted above.
     
  29. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    I'm getting a strange InputField behavior in Unity 5.0 release.

    When i dynamically create an InputField and display the first time it shows the value.

    If i then destroy the InputField and try to create it again its value does not show up.

    Anyone else seen this issue?
     
  30. Solid_Metal

    Solid_Metal

    Joined:
    Mar 25, 2015
    Posts:
    45
    still happening to me
    i try to set the inputfield value by clicking a button, it wont update on the text display, but value on the inputfield itself already updated, it'll get updated if i inputfield.gameobject.setactive(false) and make it true again

    heres my following simplify script
    Code (csharp):
    1.  
    2. public void updateValue(string temp)
    3. {
    4. inputfield.text +=temp;
    5. inputfield.textcomponent.text += temp;
    6. }
    7.  
     
  31. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Modifiying inputfield.text still doesn't work properly at 5.1.
     
  32. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    5.2 was released a while ago and 5.2.1 was released recently.

    If the issue still happens for you in 5.2.1, please file a bug report. The only reference to a bug case I see in this thread is almost a year old and that bug was fixed ages ago. :)
     
  33. DavidxK

    DavidxK

    Joined:
    May 5, 2014
    Posts:
    8
    Hey sorry to hijack this but I'm having a bug with InputField too on 5.1.3. The usual text editing stuff like selecting text, copying/pasting only works within Unity but once I create a build of the game, and run it outside of Unity, all that stuff doesn't work (tested on OS X).

    Tried upgrading to 5.2.1 but 5.2.1 is worst as it breaks Input.inputString on OS X (it always return nothing). Worst case scenario for games that need keyboard input
     
  34. POiD96

    POiD96

    Joined:
    Aug 16, 2016
    Posts:
    4
    Unfortunately the bug is still there in Unity 5.4.0f3. I'm seeing it in a much larger project, so I'll try and create a small one to reproduce and bug report.

    Bug ID: #823559

    Essentially I have an input field as a prefab that I instantiate and add under a scrollview. The value on the InputField "Text" in the Editor shows the input but the child Text object does not. I also can't seem to find a work around that works for me. :/
     
    Last edited: Aug 16, 2016
  35. rifaterdemsahin

    rifaterdemsahin

    Joined:
    Sep 3, 2016
    Posts:
    8
    so what do we do now ?
     
    deverzs likes this.
  36. executer

    executer

    Joined:
    Mar 29, 2017
    Posts:
    8
    any update?
     
    deverzs and juan-jo like this.
  37. BryanO

    BryanO

    Joined:
    Jan 8, 2014
    Posts:
    186
    Necro posting but Im having this same issue in 2019 LTS - setting the value of an inputfield.text doesn't appear to change the value of the field and so far from what I can tell doesn't fire a onchanged event either.
     
    deverzs likes this.
  38. deverzs

    deverzs

    Joined:
    Apr 6, 2021
    Posts:
    9
    Same issue as of Nov 2021
     
    vipultyagi386 likes this.
  39. MichaelEpicA

    MichaelEpicA

    Joined:
    Jun 21, 2020
    Posts:
    2
    Same issue here. Has no one fixed this?