public class MyChildrenClass : MyClass {
public int live = 10;
}
public class MyObject : ScriptableObject {
public MyClass myClass = new MyChildrenClass();
}
How can I get the MyChildrenClass properties form the SerializedProperty?
SerializedObject object = new SerializedObject(new MyObject());
SerializedProperty myClassSerialized = object.FindProperty("myClass");
//Doesnt get live property becouse it's interpretated as "MyClass"
SerializedProperty m_live = myClassSerialized.FindPropertyRelative("live");
You can iterate through child props of serialised classes by using an enumerator. You can do this a couple different ways, one being using GetEnumerator:
var childEnum = serializedObject.FindProperty("myClass").GetEnumerator();
while (childEnum.MoveNext())
{
var current = childEnum.Current as SerializedProperty;
if (current.name == "live")
{
// Do things
}
}
Or you can use Next or NextVisible with the enterChildren argument set to true:
var myClassProps = serializedObject.FindProperty("myClass");
while (myClassProps.NextVisible(true))
{
if (myClassProps.name == "live")
{
// Do things
}
}
these solutions don’t work in
public override void OnInspectorGUI() {}
Any ideas for using in a custom inspector,Hello,
I am trying both of these solutions and they do not work. Any ideas?