Hi,
I have a class that inherits from SctiptableObject. I have created a custom property drawer to allow the user to change an internal int value.
My code looks like this:
[CustomPropertyDrawer( typeof( EntityCapabilities ) )]
public class NewBehaviourScript : PropertyDrawer
{
public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
{
property.FindPropertyRelative( "capabilities" ).intValue = EditorGUI.IntField( position, property.FindPropertyRelative( "capabilities" ).intValue );
}
When i call FindPropertyRelative i get a null value however if i remove the inheritance from ScriptableObject then it works. Unfortunately i will need this inheritance in the future. Does the relative address change when i inherit from ScriptableObject?
Thanks
Karl
If someone will be in future will search information regarding theme of this thread ():
SerializedProperty.FindPropertyRelative doesn’t work in case if the type of SerializedProperty is ScriptableObject.
public class SomeSO: ScriptableObject
{
public int tSO = 5;
}
[System.Serializable]
public class TestTest
{
public int t = 5;
}
public class MainClass : MonoBehaviour
{
public TestTest _test = new TestTest();
public SomeSO _testSO
}
you can access the child members use SerializedProperty.FindPropertyRelative when you access to the member of the class not derived from ScriptableObject
SerializedProperty z = serializedObject.FindProperty("_test");
SerializedProperty zz = z.FindPropertyRelative("t");
Debug.Log(zz.intValue);
if you will try to access the member (tSO) of ScriptableObject class by use the some code you receive null.
In this case you can access it by different code:
SerializedProperty zSO = serializedObject.FindProperty("_testSO");
SerializedObject @object = new SerializedObject(zSO.objectReferenceValue);
SerializedProperty zzSO = @object.FindProperty("tSO");
Debug.Log(zzSO.intValue);
P.S>
In all cases the serializedObject is the SerializedObject of MainClass.
And remember the name of SerializedProperty can differ from it name at C# script