Hello, I have this problem where serialized property’s label changes when expanded and I can’t figure out why.
Here is the example code:
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[CreateAssetMenu(menuName = nameof(ScriptableObject) + "/" + nameof(Test))]
public class Test : ScriptableObject
{
public CustomObject<ComplexObject> CustomObject;
}
[Serializable]
public class ComplexObject
{
public int a;
public float b;
}
[Serializable]
public class CustomObject<T>
{
public T Value;
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(CustomObject<>))]
public class CustomObjectDrawer : PropertyDrawer
{
private const string k_ValuePropertyKey = "Value";
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
SerializedProperty valueProperty = property.FindPropertyRelative(k_ValuePropertyKey);
EditorGUILayout.PropertyField(valueProperty, label);
EditorGUI.EndProperty();
}
}
#endif
And here are screenshots:
As you can see the label changes when field is expanded. I can’t undestand why it happens, I guess the EditorGUI.PropertyField method draws something like base implementation for expanded fields.
How can I fix it so it will display the label I want?
Many thanks!