Howdy yall,
My inventory system is a bunch of buttons in layout groups. I have a search input field, but I am having trouble capturing the string there… and Unity isn’t “pointing straight at my problem.”
This works to report all the button items’ labels:
void UserSearchButton_onClick()
{
print("User Search: " + userSearchText.text);
foreach (Transform child in activatedMenuTransform.transform)
{
print("Text Object Name : " + child.gameObject.GetComponentInChildren<Text>().name);
}
}
But this reports
“NullReferenceException: Object reference not set to an instance of an object”
void UserSearchButton_onClick()
{
print("User Search: " + userSearchText.text);
foreach (Transform child in activatedMenuTransform.transform)
{
if (child.gameObject.GetComponent<Text>().text.Contains(userSearchText.text))
{
print("Text Object Name : " + child.gameObject.GetComponentInChildren<Text>().name);
}
}
}
I also messed with
if (child.gameObject.GetComponent().text.IndexOf(userSearchText.text) >1)
but I get the same error.
Any ideas would be appreciated!