- Home /
Question by
Qubitz · Jun 26, 2018 at 09:34 PM ·
c#propertydrawerattributeeditor scriptingpropertyfield
Custom attribute not respecting property's PropertyDrawer
I have conflicting PropertyDrawer
s. I created a simplified example:
SweetAttribute
has aPropertyDrawer
that callsEditorGUI.PropertyField
Awesome
struct has aPropertyDrawer
that callsEditorGUI.Toggle
Here's the code to explain:
Code
using System;
using UnityEngine;
using UnityEditor;
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class SweetAttribute : PropertyAttribute
{
public string content;
}
[CustomPropertyDrawer(typeof(SweetAttribute))]
public class SweetDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Debug.Log("Drawing from SweetDrawer.");
var content = (attribute as SweetAttribute).content;
EditorGUI.PropertyField(position, property, true);
}
}
[Serializable]
public struct Awesome
{
public bool isAwesome;
public int data;
}
[CustomPropertyDrawer(typeof(Awesome))]
public class AwesomeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Debug.Log("Drawing from AwesomeDrawer.");
bool value = false;
value = EditorGUI.Toggle(position, value);
}
}
Then I have the MonoBehaviour
that combines SweetAttribute
and Awesome
:
public class Test : MonoBehaviour
{
[Sweet]
public Awesome test;
}
In Test
's inspector, AwesomeDrawer
's OnGUI is never called when SweetAttribute
exists. Please help me understand why this is. I'd like the toggle from AwesomeDrawer
to show up in the inspector.
capture.png
(21.2 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612165538im_/https://answers.unity.com/themes/thub/images/avi.jpg)