CodeMonkey
CodeMonkey

Reputation: 1835

Only Getting a Static String for OnValueChanged of InputField

I have an InputField and I'm targeting my "FindSoftware" function for OnValueChanged but it won't pass the string of the InputField. I can manually type what it will pass beside where I select which function to call ("This_is_Static_Boo..." in the example below), but that's no good since I want the text I am currently typing into it. How do I make it dynamic?

public void FindSoftware(String s)
{
    Debug.Log("Updated string = " + s); // Always blank or whatever I statically tell it to be
}

enter image description here

Upvotes: 0

Views: 630

Answers (1)

derHugo
derHugo

Reputation: 90580

There are two types of callbacks for UnityEvents

When configuring a UnityEvent in the Inspector there are two types of function calls that are supported:

  • Static. Static calls are preconfigured calls, with preconfigured values that are set in the UI. This means that when the callback is invoked, the target function is invoked with the argument that has been entered into the UI.

  • Dynamic. Dynamic calls are invoked using an argument that is sent from code, and this is bound to the type of UnityEvent that is being invoked. The UI filters the callbacks and only shows the dynamic calls that are valid for the UnityEvent.

So when setting up your method call just make sure you select the one from the Dynamic section on the top where all callable methods are listed that take string (or the given type(s)) as a parameter(s).

enter image description here

Upvotes: 3

Related Questions