I have an input field and event that calls a function when I press enter.

public Text theText;

I take the Text part of the input field (connect them in editor), display the content and set new value to some string.

Debug.Log(theText.text);
theText.text = "new text";

I get the contents displayed, but the value isn’t changed.

Why am I able to read but not write to it? And how do I fix this?

EDIT:
To clarify, I’m talking about the new ui system. I tried creating a new scene, with just that input filed with a script (attached to it) that contains the 2 lines I posted earlier (I connect the text field, child of the input field, to “public Text theText;” in editor). And it’s not changing text, just showing it. I suppose I could create a GUI.TextField in OnGUI(), that way I could surely change the text value. But the current way I’m trying now worked fine few days ago, I don’t get what could not be happening…

For those who are interested the problem was that I tried to directly edit the UI.Text object, which was a child of an UI.InputField object.
When I replaced public Text theText; with public InputField theText; , connected the actual InputField to that variable, not it’s child the Text object, tried to change it with theText.text = "new text"; it worked fine.

Your code looks OK so if this doesn’t work then try posting more of the script so we can see what’s going on, that said…

public variables are overridden in the inspector, try setting it to private, call the Text object something unique and using GameObject.Find to find it e.g.

private Text theText;


//in start
theText = GameObject.Find("uniqueTextName").GetComponent<Text>();

example in C#

Just as a note, I had the same problem and found that for some reason my input field was under the canvas and not the panel. Dragging it under the panel resolved the issue.

I have the same problem :frowning: