I genuinely can’t find the solution to this anywhere despite it being such a simple problem so here’s the issue. I have an Input Field on the canvas that I’ve set the content type to integer and I have a script that’s supposed to collect that integer value, but I can’t seem to collect it no matter what I try. When I start the game and input a value into the field the printed result is always 0. If I switch the content type to standard and the function in the script to collect a string it works perfectly fine, but I need this field to be integer only.
The function just looks like this rn:
public void ReadWidthInput(int input)
{
Debug.Log(input);
}
The example you have linked shows you calling a method via the event ‘On End Edit’. The way you have it configured is you have it calling said method with a parameter of 0. You can see the 0 in the image:
The event in question doesn’t pass along the input field’s contents as an integer, so it doesn’t know how to call that method. This is why it gives you the option to define the parameter passed to that method.
If I recall correctly that event is the ‘InputField.EndEditEvent’ which passes the input as a type ‘string’ as a parameter. You can try changing the parameter to an ‘string’, reconfigure it to call that, and it should end up looking something like this:
Note how there isn’t a field to define the parameter. The UnityEvent editor doesn’t offer a parameter field for it because the parameter is defined by the event (the string in this case).
Also keep in mind that just because you restricted it to integer doesn’t mean it’s going to be stored as integer or passed as integer. That content type just says what set of characters are allowed in the string. You’ll still have to parse it to an int via something like int.Parse or int.TryParse: