How to pass string from input field using "OnSubmit (String)"

I’m using the new GUI system in the 4.6 Beta.

I’ve added a InputField UI element. I want to pass the string that is typed in the input field to the function I have created below. I’ve dragged the Gameobject containing the component with said function onto the On Submit (String) event, selected the public function below. The string isn’t getting passed, also , the function isn’t even being called.

Any Ideas?

	public void SetClientAppName (string name){
		Debug.Log("Called :  " + name );
		clientAppName = name;
		RestartSyphon ();
	}

For anyone having this problem in the future.

On the InputField component, there is a checkbox for “Multi Line”. Every time I pressed enter to submit text I was of course just starting a new line.

What this didn’t solve is how to pass the string entered in the checkbox to my SetClientAppName function. I still haven’t found a way to do this using OnSubmit (string) as this just passes whatever string is entered into the textbox to the right of the drop down to choose the function.

Instead I created a public input field and listener like so. Remember to include the “using UnityEngine.UI” header.

public InputField newClientName;

void Awake (){
	newClientName.onSubmit.AddListener((value) => SetClientAppName(value));
	}

public void SetClientAppName (string name){
	Debug.Log("Called :  " + name );
	clientAppName = name;
	RestartSyphon ();
	}

You can have the parameter of the function be a UI.Text component, and then add the reference of the same Text object as the value of the parameter your passing in.

public void UpdatedTextBox(UnityEngine.UI.Text newValue)
{
        Debug.Log("Text was updated to: " + newValue.text);
}

As you already noticed, hitting Enter just creates a newline when the text is set to Multiline; according to threads on the forum, in the next version they added a selection for how to handle Enter.

As for the text being submitted, make sure to select function in top section “Dynamic string” and not bottom section “Static Parameters”. I had the same issue at first and it took me a while to figure out; apparently you can use either dynamic or static string parameters and I had selected the function in static.