Home > database >  TextMeshPro Input field - how to set wrapping to enabled?
TextMeshPro Input field - how to set wrapping to enabled?

Time:11-25

What I have for now: I have an input field that is supposed to work like this: when it's not focused, there is a multiline text, for example: "Write your\nnumber here!". When focused, it's replaced by empty line and user can enter an integer number (Content Type = Integer Number). On finishing input (OnEndEdit) I use the input to spawn some GameObjects and then replace the text again with "Write your\nnumber here!". Editor screenshot: screenshot

Unsure if that's relevant, but just in case: The only way I was able to add the newline was to open the prefab as text in notepad and copy the text from placeholder directly into the function argument field (just putting it with newline character in editor, eg "Write your\nnumber here!" doesn't work for some reason), i have to directly put " \n " into the prefab file, or else it basically treats it as unicode "005C 006E" and escaping the \ doesn't help.

Right now it works as I expect. However, now I want to dynamically change the placeholder text, so I don't know where the newline will be and I would like for TMP to wrap the text for me, same as it does in Text component with Wrapping enabled. The problem: setting Placeholders' Or Texts' wrapping to true has no effect - it gets reset to false immediately when starting scene, probably from InputField. Input field has no "wrapping" option for me to specify. This link suggests using multiline, but 1) that's for unity's input field and not TMP; 2) TMP seems to have the multiline option, but I can't set it (I can see it if I switch the inspector to debug mode, but on change it immediately switches back to single line).

So: how do I use TMP's wrapping - enabled on InputField without it getting reset to disabled? Either both the user input and placeholder, or just on placeholder itself - doesn't matter.

CodePudding user response:

MultiLine is only available if the Content Type is set to Standard or Auto Corrected.

As soon as you set the input type to Integer Number it basically behaves just like an integer field in the Unity Inspector: No line wrapping but rather overfloating and scrolling to the right.

Alternatively if you need multi lines you could set the Content Type to Custom and then fully flexible adjust it to your needs like e.g.

  • LineType : Multi Line Newline
  • Line Limit: 0
  • Input Type: Standard
  • Keyboard Type: Default
  • Character Validation: Integer

And in general: Of course you also can't set a text to an input field that only accepts integer numbers ;) Rather set your placeholder text in the Placeholder object!

Anything that is applied to the Placeholder will be displayed automatically as long as there is no value typed in the input field!

  • Related