gasgiant / Markup-Attributes

A Unity Editor extension for customizing inspector layout with attributes.
MIT License
289 stars 11 forks source link

Can't apply markup attributes to parent class #8

Closed 3ternal closed 2 years ago

3ternal commented 2 years ago

Hi,

I ran into an issue, and I'm unsure of whether it's a bug or whether I'm simply making a mistake.

Try the following setup:

public class TestParent : MonoBehaviour
{
    [TitleGroup("Group A")]
    [SerializeField] string field1;
    [SerializeField] string field2;
}
public class TestChild : TestParent
{
    [TitleGroup("Group B")]
    [SerializeField] string field3;
    [SerializeField] string field4;
}

In this situation, only Group B is appearing in the editor. The "Group A" heading doesn't appear. The same is true for Foldouts etc.

https://i.imgur.com/cQieGHw.png

I'm testing this in a fresh project, so my editor scripts are as you suggested in the docs.

[CustomEditor(typeof(MonoBehaviour), true), CanEditMultipleObjects]
internal class MarkedUpMonoBehaviourEditor : MarkedUpEditor
{
}

[CustomEditor(typeof(ScriptableObject), true), CanEditMultipleObjects]
internal class MarkedUpScriptableObjectEditor : MarkedUpEditor
{
}

This is Unity 2021.3.4 and MarkupAttributes 0.5.0.

gasgiant commented 2 years ago

Hi!

That's a bug. I've probably messed something up with reflection. I'll fix it this week.

gasgiant commented 2 years ago

Hello again!

Turns out it's not really a bug. You declared your fields in the parent class as private, so they are invisible in the child class (though Unity still serializes them). You can just declare stuff protected and then attributes will work.