PropertyDrawer Issue

Hey, I’m probably missing something, but after spending an entire day on this I need some help.
It looks like the Unity doc for the PropertyDrawer is either out of date or wrong? Unity - Scripting API: PropertyDrawer
I created an object:

[System.Serializable]
class MyObj
{
[SerializedField]
public test {get; private set} = "test_value";
}

And my property drawer

[CustomPropertyDrawer(typeof(MyObj))]
internal class MyObjDrawer: PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
 var test = property.FindPropertyRelative("test");
//This here is null??
}
}

The FindPropertyRelative is always returning null. I tried finding some info on other threads, but everyone seems to be using ScriptableObjects and I’m not looking to create a custom editor window, I’m looking to change a property only. Can someone help me out? Thanks in advance!

PS: This is not the actual code, I can’t put it here, but the property drawer itself works only the getter doesn’t work.

We dont support serializing properties, they need to be fields or a property with a backing field.
See Serialization of properties

3 Likes

Oh boy, I completely forgot that. Thank you!

1 Like

Thank you for helping me out as well, you made my day.

thanks for info