Hi,
i’m trying to set the value of a component at runtime. I get the information from a SerializedProperty at edit time this way:
string propName=property.name;
For a concrete example, for CanvasGroup, the property “Interactable” returns “m_Interactable”, which seems to be the private variable used as getter for the property.
But then at runtime (no SerializedProperty available) when i try to retrieve that “m_Interactable” field, it doesn’t exists!
Inspecting all the properties returned at runtime, i have one “get_Interactable”, but no way to link the value from the editor at runtime. BTW, the component doesn’t have any field, only properties.
I presume there’s a code that transform all the public fields declared in a component to properties.
This is the code i’m using to retrieve the information (c is an instance of CanvasGroup)
Debug.Log(c.GetType().GetProperty("m_Interactable"));//Returns null
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static;
PropertyInfo[] properties = c.GetType().GetProperties(flags);
Debug.Log(c.GetType().GetProperty("m_interactable"));
foreach (PropertyInfo propertyInfo in properties)
{
Debug.Log(" Property: " + propertyInfo.Name+" "+propertyInfo.GetGetMethod(true));
}
Is there any way using reflection to obtain the property declared in the SerializedProperty.name (or propertypath)?
Thanks!