I am having a problem in unity setting up a search field. I will post pictures down reggarding my problem but first let me quickly explain what is going on.
I have input element in my ui and i have working search function ready to use. The problem is that the string i feed my search function with is assigned from the inputfield text element value, which appears to be always one step behind.
What i mean is when I type "Wooden door" inputfield value is "Wooden doo".
It is quite annoying and I have no idea what is going on. Please point me into right direction.
Let me post the pictures with quick descriptions.
My problem (item I am looking for is named "Wooden door"):
Second image of my problem (door item should not be present):
Finaly my ui settings and code:
My search control script:
using UnityEngine;
using UnityEngine.UI;
public class SearchControl : MonoBehaviour
{
public InputField inputField;
public Text searchInput;
private void Start()
{
inputField = GetComponent<InputField>();
searchInput = inputField.textComponent;
}
public void Search()
{
if (searchInput == null)
{
Debug.LogWarning("Can't find search field.");
return;
}
//TODO: text value is always one letter behind.
string searchVal = searchInput.text;
Debug.Log("Searching value: " + searchVal);
CraftingManager.instance.RenderSearchedRecipes(searchVal);
}
}
I think there is some kind of character "verification" going on there and the real value of that text field is really one letter behind (since i assign it befor it gets verified). But that is not acceptable and I have no idea what can i do to avoid it. Thank you for any help!
searchInput
are declared & populated). Have you tried searching for past Q&A with users experiencing a similar issue? \$\endgroup\$