- Home /
How to get InputField Text from prefabClone?
I have a prefab that is instantiated when I mouseDown On the prefab I have button that opens an InputField, I enter Text and Save it to a json file. I am trying to get the Prefabs InputField Text that I set so I can write it to the file, but it keeps failing
I can see the Prefab > InputField Text field is empty, but the Prefab(Clone) has the Name in the Text field
On the prefab is a script and i have the following:
public InputField input and then I drag the InputField on to the script variable in Unity Component
string str = inputField.text; is always NULL and it is null on the Prefab, but in the clone it is populated.
Not sure what I am doing wrong, but any info needed, I will try my best to give out.
Answer by Fritched · Jan 13, 2021 at 03:05 AM
Its a bit difficult to tell what the problem may be, but I'm guessing its a reference issue. You mentioned having a script on your prefab. That script should have reference to the input field. When you create an instance of your prefab you can do a GetComponent() to get a reference to the script on that prefab. With that reference you should be able to get the text that is inputted into the input field. I created a small example project for this. Take a look and see if it helps.
https://drive.google.com/file/d/1OvNSpbRijrzvzw7oUgvBGSNJzbzvaFG3/view?usp=sharing
Your answer
![](https://koobas.hobune.stream/wayback/20220613023204im_/https://answers.unity.com/themes/thub/images/avi.jpg)