Set Text of Input Field?

I can read the content of an Input Field.

mystring.text=inputfield.text.text;

But i need to change the content of the input field. And this one does not work. It doesn’t give a warning, but simply refuses to set the text:

inputfield.text.text=mystring.text;

Is it even possible to change the text of the input field?

inputfield.value is what you want to look at. The text.text will not be the full value of the input field but only the visible portion

Many thanks, works like charm :slight_smile:

Hm, nope, I get an error now from time to time:

System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
  at System.Collections.Generic.List`1[UnityEngine.UICharInfo].get_Item (Int32 index) [0x0000c] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633
  at UnityEngine.UI.InputField.CalculateTextVisibility (UnityEngine.TextGenerator result, System.Int32& newDrawStart, System.Int32& newDrawEnd) [0x001f5] in C:\BuildAgent\work\d63dfc6385190b60\Extensions\guisystem\guisystem\UI\Core\InputField.cs:1261
  at UnityEngine.UI.InputField.UpdateLabel () [0x00121] in C:\BuildAgent\work\d63dfc6385190b60\Extensions\guisystem\guisystem\UI\Core\InputField.cs:1074
  at UnityEngine.UI.InputField.DeactivateInputField () [0x0005f] in C:\BuildAgent\work\d63dfc6385190b60\Extensions\guisystem\guisystem\UI\Core\InputField.cs:1638
  at UnityEngine.UI.InputField.OnDeselect (UnityEngine.EventSystems.BaseEventData eventData) [0x00007] in C:\BuildAgent\work\d63dfc6385190b60\Extensions\guisystem\guisystem\UI\Core\InputField.cs:1650
  at UnityEngine.EventSystems.ExecuteEvents.Execute (IDeselectHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in C:\BuildAgent\work\d63dfc6385190b60\Extensions\guisystem\guisystem\EventSystem\ExecuteEvents.cs:108
  at UnityEngine.EventSystems.ExecuteEvents.Execute[IDeselectHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) [0x00087] in C:\BuildAgent\work\d63dfc6385190b60\Extensions\guisystem\guisystem\EventSystem\ExecuteEvents.cs:257
UnityEngine.EventSystems.EventSystem:Update()

Then thats a bug, could you submit your project that causes this.

Yes, looks like a bug. Will have a look to reproduce it in an example file. The current project is already a bit too big to be useful for a bug case.

Please give me a few hours to sort things. I’ll submit it then, and will place the case number in this thread.

I have reduced the problem to a small example file. The cause seems to be the character limit. I have submitted the problem as a bug report yesterday. But didn’t receive a message from QA yet what bug number it is. So just in case, here comes the dataset as an attachment too. The example project and a screenshot.

Load the project, run the app, in the input field type in a value that is above the character limit of the input field, and you will get a out of range exception when you hit enter.


1785765–113572–ArgumentOutOfRangeException.zip (175 KB)

perfect that helps alot :slight_smile:

Hm, seems that the bug didn’t made it into the tracker. Two days gone, no confirmation mail. Should i resubmit the bug report? Or is this thread here enough?

id like to think this thread is enough, but i have a bad feeling i’ll forget about it in amongst the rest of the work being done.

Thanks Phil,

I’ll resubmit it :wink:

EDIT, done. case number http://fogbugz.unity3d.com/default.asp?635790_l4h5jlf0f0avnt3s

1 Like

I can’t seem to get GetComponent().value to work? Any Ideas?

Send me a message if you ever figure this out. Been trying to figure this out for days now

Wouldn’t it make more sense to hook into the OnValueChange event?

isn’t onvaluechange event only when the value is being changed? The problem im having is I can’t even select it to change it

You mean you can’t even see text? Make sure you add a Layout Element and set a MinHeight to something high enough to prevent the text object from clipping.

When I click on user name there is no carrot blinking can’t type in it.
Just keeps the placeholder

What is that “input manager” component?

empty script. I added it cause was trying to activate the text field to make it selectable lol

I hate to cross-promote, but maybe use some UI wrapper library that handles the crazy for you? :wink:

I noticed your Pos Y is -300, is this expected? Also check the design tab and make sure the text field and its children are where you think they are. Sometimes you’ll see they have a height of 0, or are way out in lala land outside the camera.