- Home /
Cannot accessing text in InputField Array
here is some of my code
public InputField[] names = new InputField[4];
playerParty[count] = createCharacterData(names[i].text.text, (int)(sliMember[i].value), getClassToggle(tgMember[i]));
and i got "NullReferenceException: Object reference not set to an instance of an object" from names[i].text.text but i already put inputFields in it.
Can someone teach me what i did wrong
ps. i use 5.0.0b9
the type Input field doesn't have a text property/field directly on it. Should it be:
names[i].guiText.text
use only one text:
names[i].text
or
names[i].textComponent.text
Both are working!
Assu$$anonymous$$g that you are using the new Unity UI.
In the version I'm currently using (4.6.0f2) @jenci1990 is right.
guiText shouldn't be used because this is from the old (legacy) GUI system.
I believe that in an older version of the beta, the textComponent variable didn't exist, and text was that variable ins$$anonymous$$d. I'm not sure though, and can't check this atm. But if your code doesn't give compiler errors then this is most likely the case.
If this is true, and if names[i] indeed isn't null, then names[i].text is. to fix that go to the inspector of your InputField and check the text/textComponent field. That field shouldn't be empty ;)
I still cannot fix it so i move back to 4.6.
Thank you everyone
Answer by SuperMasterBlasterLaser · Dec 01, 2014 at 02:22 PM
To change text inside InputField you must do something like this:
myInputField.value = "My String";
Your answer
Follow this Question
Related Questions
yield WaitForSeconds(1) ends with this error:ArgumentException: method return type is incompatible 2 Answers
Unity-Added Lines 1 Answer
My script won't let me change the text of a UI object 4 Answers
error CS0029: Cannot implicitly convert type 'string' to 'int'... I EVEN ADDED .ToString(); 1 Answer