Let`s talk about Text and InputField

All we know that we can edit string value of the Text with this code:

public Text text1;
//code
text1.text = "blablabla";

also we can get value from it;)

Okay, thats awesome, but what about InputField? Lets see
As in Text we also can edit this string value:

public InputField inputField1;
//code
inputField1.text = "blablabla";

of course, we can get value from it;) really???:hushed:

Stop man, what you talking about?

As you know, InputField have few childrens in hierarchy - “Placeholder” & “Text”
Text has string value of inputted text in InputField, logically, we can use it!
But thete`s something wrong. I can get value of this Text:

public Text textInsideInputField; //text from InputField
public Text text2; //simple text
//code
text2.text =  textInsideInputField.text;

Yeah! Success!

But what about we want change this Text component directly :

public Text textInsideInputField; //text from InputField
public Text text2; //simple text
//code
textInsideInputField.text =  text2.text;

It havent any error message, but value doesnt change.
I came to the conclusion that when try to access to the Text object in InputField its read only. (its strange)
This is a bug, or it should be?:face_with_spiral_eyes:

In this case the InputField is controller the text components that come with it.
The text-components are not read only but the InputField will overwrite the text values with the data it holds.
If you like to change the text of the text objects you have to change the InputField.text value like in your example.

There are some cases in the ui where a controller class is controlling and managing other components values ,like the layout components that will overwrite and manage the Recttransform values.

1 Like