Hi,
I’m working on a Unity3D game and after updating to version 5.4 (from 5.3) I noticed that multi-line InputField is behaving strangely. It stopped scrolling the text correctly. When text is longer than it’s possible to show in the input area, and you keep typing, it doesn’t scroll down like it used to. You can type, and until you go to another line, the text is invisible. When you go to the next line, the line you have finished appears, but the “new last line” is hidden.
Any idea how to go around this problem other than forcing empty \n at the end of the text?
Here are the details of the input field I work with (though I’ve replicated the problem with brand new InputField created using editor): Content type: Standard Line type: Multi Line Newline Character limit: 0 (increasing it to 1000 doesn’t change anything)
Associated text parameters: Horizontal overflow: wrap Vertical overflow: truncate
I have the exact same issue, also in Unity 5.4. Should this be submitted as a bug?
I don’t think we did. We had to fix this asap since our release date was creeping up on us so we didn’t have time to report it. We finally used TextMeshPro to deal with this issue.
I got the following to get about 90% functionality: (the following numbers in the RectTransforms are to get 2 lines of display for a 14pt Arial font. You can fiddle with them for other fonts/sizes/ number of lines to view).
- Create InputField - Set it to MulitLine-NewLine
- Change the RectTransform Height to 35
- Add A RectMask 2D component
- In the Text Child of the Input Field Add a Content Size Fitter and Set Vertical Fit: Preferred Size
- In the Rect Transform (using shift and alt) Click Bottom left and Stretch (this will be the button directly above the bottom right corner’s double stretch that its currently set to.)
- Set Left, Pos Y and Right all to 3.
Now you can type as many lines as you want, and see the bottom 2. The extra lines will scroll up and above the input field but mask hides them. If you delete lines the text will scroll back down. Thats the 90%. Now for the bad news: just using the arrow keys to move the caret around will move it up and out of the input field into the masked area.and it will be visible and blinking there. (but you can’t see any text of course). This is fixable with some work.
Looking at this file:
https://bitbucket.org/Unity-Technologies/ui/src/0155c39e05ca5d7dcc97d9974256ef83bc122586/UnityEngine.UI/UI/Core/InputField.cs?at=5.2&fileviewer=file-view-default
It seems that the caret position is gettable. You could then catch all the events that move the Caret (Keys: Up/down/left/right/home/end and Mouse clicks) and just get the caret position to determine what line its on. Then move the RectTransform of the Text Compent’s YPos up and down based on the caret position.
Another option (one that hopefully the unity developers get to) is to look into the UpdateLabel and
SetDrawRangeToContainCaretPosition functions and see where the bug is and fix it. Then you could attach the fixed InputField script to a default InputField and your back in business.
1 Like