- Home /
Getting PropertyAttribute from PropertyDrawer.OnGUI
Hi guys
I've written a custom PropertyAttribute class and I want to use a custom PropertyDrawer class to access and display data on the PropertyAttribute.
So far I have something like this:
[Serializable]
public class CustomPropertyAttribute : PropertyAttribute
{
public A a {get; set;}
public B b {get; set;}
}
[CustomPropertyDrawer(typeof(CustomPropertyAttribute))]
public class CustomPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty prop,
GUIContent label)
{
// How do I access the CustomPropertyAttribute properties here?
}
}
How can I get at the CustomPropertyAttribute from inside the OnGUI method?
The documentation suggests using the "attribute" property:
But then says it isn't applicable with custom drawers (it returns null when I try it), so I fail to see when it would ever be useful.
I've also tried:
prop.serializedObject as CustomPropertyAttribute;
But the compiler isn't happy with the conversion.
Can anyone please explain how I can use the PropertyDrawer effectively?
Your answer
![](https://koobas.hobune.stream/wayback/20220613144041im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Display Custom Inspectors for each class in a List<> 1 Answer
SerializedProperty isn't being detected as an array? 1 Answer
How to find the first child serializedProperty inside a PropertyDrawer 1 Answer
How can I correctly draw properties instead of fields in a custom property drawer? 0 Answers
How to find property of a serializeObject that has the same name with a field of another property? 1 Answer