gasgiant / Markup-Attributes

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

Inherited fields don't seem to use markup attributes #15

Closed mikkelens closed 9 months ago

mikkelens commented 1 year ago

This is my code in my base class (deriving from MonoBehaviour, which I have made a custom editor for like installation guide says): image I'm trying to use the ReadOnly attribute on a field like shown above.

It looks fine in the base class ("Physical Box")... image

...but not in a derived class ("Player"). image ("Grounded" below is using a custom property drawer, ignore it)

I tried looking for any mention of this in the readme, but I didn't see it. Sorry if this is something that isn't intended to be possible.

gasgiant commented 1 year ago

Hi! For it to work you'll have to make the velocity protected rather than private.

mikkelens commented 1 year ago

Ah. I wasn't aware that could affect attributes. Can private protected work too?

gasgiant commented 1 year ago

I think it shoud, but you can test, of course. The property must be accessible from the child (via reflection) to get any attributes. Otherwise Type.GetField will return null. I could, conceivably, step up the hierarchy from the type upwards and accumulate the attributes from the parent. But I'm not sure it is really necessary.