Quite simple. I am trying to get the variables values from the editor window and see if it matches a string. I can’t seem to figure out what is going wrong in this function of mine.
bool ComponentFeildValueContainString(Component component, GameObject target)
{
System.Type objType = component.GetType();
foreach (System.Reflection.PropertyInfo pi in objType.GetProperties())
{
try {
if (target.name.ToLower().Contains("eyeboss"))
{
Debug.Log(target.name+": "+pi.Name+": "+pi.GetValue(component,null));
}
if (pi.GetValue(component,null).ToString().ToLower().Contains(Search.ToLower()) == true)
{
return true;
}
}
catch(System.Exception ex)
{
continue;
}
}
return false;
}
It only seems to return the unity built in properties and not my exposed variables. What am I missing?
Here is a picture of the variables seen in the inspector

Here is what I am getting from the logs:

Got it. This is what it needed to be:
bool ComponentFeildValueContainString(Component component, GameObject target)
{
System.Type objType = component.GetType();
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var properties = objType.GetFields(flags);
foreach (var prop in properties)
{
try {
if (target.name.ToLower().Contains("eyeboss"))
{
Debug.Log("VAR:"+prop.Name+"VALUE:"+prop.GetValue((object)component));
}
if (prop.GetValue((object)component).ToString().ToLower().Contains(Search.ToLower()))
{
return true;
}
}
catch(System.Exception ex)
{
continue;
}
}
return false;
}