gasgiant / Markup-Attributes

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

Not working with serialized property backing fields #21

Open lorenblue opened 9 months ago

lorenblue commented 9 months ago

Hey! Hopefully I am wrong, but the following doesn't seem to produce any desired results for me:

[field: SerializeField] [field: Box("Group")] public bool TestProp { get; private set; }

lorenblue commented 9 months ago

Unity 2022.3.12, and it shouldn't be improper setup on my end because everything works fine in the same class as long as it's a public field and not a prop.

gasgiant commented 9 months ago

Hi! I don't think Unity serializes properties and so MarkupAttributes do not work on them.

gasgiant commented 9 months ago

It should be a field to work properly. Though it doesn't have to be public, private/protected [SerializeFiled] marked ones work as well.

lorenblue commented 9 months ago

Unity most definitely serializes the backing fields though. The serialization aspect of the snippet I added above works, and I use it all the time. Cheers!

gasgiant commented 9 months ago

I see. Either it did not do it before or I was misguided. Whichever it is, I only check for attributes the FieldInfo for each SerializedProperty, so the attributes on properties won't register. Relevant code is here: https://github.com/gasgiant/Markup-Attributes/blob/main/Assets/MarkupAttributes/Core/Editor/EditorLayoutDataBuilder.cs

gasgiant commented 9 months ago

Or, if I understand the syntax correctly, the attributes are applied to the backing field. In this case it won't have the same name as the SerializedProperty, so GetField would return null.

lorenblue commented 9 months ago

Gotcha. Do you think this could be something you support? All good if not, I was just hoping to switch away from Naughty Attributes as yours seems to handle nesting way better.

gasgiant commented 9 months ago

I think I can do this relatively easily, if the name of the underlying property can be relied on. I'll let you know about the outcome.

lorenblue commented 8 months ago

Sounds good, cheers!

MJRamon commented 7 months ago

Sgining up for an update for the solution.