Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro Placeholder vs Input Text in Input Field

Discussion in 'UGUI & TextMesh Pro' started by ledbetterMRI, Apr 17, 2020.

  1. ledbetterMRI

    ledbetterMRI

    Joined:
    May 29, 2019
    Posts:
    25
    I need some help and have some feedback based on my recent experience with the TMPInputField component in 2019.2 + TMP 2.0.1.

    TL;DR: How do I manually control the placeholder text value and the text input value of the a TMP Input Field? Everything I seem to try with the provided API doesn't work. Maintaining references to the individual UGUI components and setting their values doesn't work.


    Summary of my problem:
    I'm creating a searchable dropdown by combining TMPInputField with TMPDropdown. I set the actual input text (or so I would expect) via inputField.text when dropdown.OnValueChanged gets invoked. Easy.

    Initial problem on unity application start. dropdown.OnValueChanged gets invoked when the options get populated in the Awake method. That's okay, I can clear that.

    What's odd is the placeholder text component gets the value change, not the standard text component. This happens regardless if the assignment is via ".SetTextWithoutNotify()" method or ".text" property. This was unexpected by the implied naming conventions and what is displayed in the inspector.

    My complications with the InputField class were compounded by the somewhat confusing choice to make the "placeholder" property of type 'Graphic'. I understand going with the parent class makes it easier to opt between a visual placeholder or a text-based one, but there's no user manual documentation to explain this choice (that I could find) and I think it serves to complicate the TMP workflow a bit.

    Feedback:
    • The need to cast ".placeholder" to a TMP UGUI component just to access its text value through code... it's messy and not self-documenting. I would expect InputField inspector values, its public class properties, and the standard TMP_InputField component created from the right-click context menu to mirror each other in structure and accessibility. The subtle mismatch between all of these makes working on inputfields through code initially confusing and unintuitive.

    • TMP needs a user manual-style explanation like the main Unity docs. The API format isn't great for explaining general usability.

    • Setting the ".text" property or using "SetTextWithoutNotify" method should, IMHO, set the actual input text value and only the input text value. Docs say that this sets the current text value, but it should at least say "the currently displayed text value". This is a subtle but important distinction. The current docs become ambiguous with 'current' and 'text' - does that mean the current text input value? Or the currently displayed text value? You'd never know this one method could be setting the placeholder value or the input text value at any given time.

    • In lieu of the above point, it would be nice if the InputField class had an explicit "SetPlaceholderText" method and an explicit "SetInputText" method.

    • There's also a lot of sparsely documented fields/properties on the docs. Just happened to notice as I was reading through.
    Thanks for taking the time to read and consider my feedback! I think TMP is an otherwise great addition to Unity and I appreciate all the flexibility it provides to UI design.
     
    Last edited: Apr 17, 2020
  2. darkhelmet2005

    darkhelmet2005

    Joined:
    May 26, 2014
    Posts:
    9
    I seem to be a bit late on the response, but this is how I set/get the placeholder field via text. Hope this helps.

    yourTmpField.transform.Find("Text Area").transform.Find("Placeholder").GetComponent<TMP_Text>().text
     
    alexiskennedy and alishahbukhari like this.
  3. alexiskennedy

    alexiskennedy

    Joined:
    Sep 21, 2016
    Posts:
    4
    If I understand correctly, it's now possible to access it via the API in Unity 2023.x, but the team have said they're not planning to backport it to 2022.x.