Assign value to Input field

Hi all,

I am working with latest version of unity and have problems with assigning value to an Input filed from script. I made a custom inspector window. There I have one textbox. A made UI Input field in scene as well. My goal is that if I something write into textbox in the custom inspector window I’d like to see that text in Input field in the scene.

In inspector window I have something like:

[CustomEditor(typeof(InitFormObject))]
public class InitFormEditor : Editor {

    private InitFormObject _initForm;

    private void OnEnable()
    {
        _initForm = (InitFormObject)target;
    }

    public override void OnInspectorGUI ()
    {
        GUILayout.Space(8);
        _initForm.apiKey = EditorGUILayout.TextField ("Api Key", _initForm.apiKey);

        if (GUI.changed) {
            _initForm.Changed();       
        }
       }
}

Where InitFormObject is MonoBehaviour object below.

public class InitFormObject : MonoBehaviour {

    public string apiKey;
    public Text _apiGuiText;

    public void Changed()
    {
        Debug.Log ("Changed api key: " + apiKey );

        GameObject apiText = GameObject.Find ("TextApiKey");
        Debug.Log ("apiText is there " + (apiText != null));

       
        _apiGuiText = apiText.GetComponent<Text>();
        Debug.Log ("apiGuiText is there " + (_apiGuiText != null));

        _apiGuiText.text = apiKey;

        Debug.Log ("apiGuiText.text: " + (_apiGuiText.text));

GameObject called “TextApiKey” is object in scene inside my input field. Inside this object should be Text component which is true (component is not null). When I insert some text into the component (_apiGuiText.text = apiKey) and print it out afterwards, the text from _apiGuiText is always empty and nothing is written into Input field. Can anyone tell me, what am I doing wrong? I am a newbie with unity.

Ok I have a little update. The problem was that I called bad GameObject. Instead of calling “TextApiKey” I should called my Input field and there called inputField.text = “test”.