Skip to content

Optional Order parameter for GroupAttribute - #115

Open
Preliy wants to merge 2 commits into
annulusgames:mainfrom
Preliy:group_order
Open

Optional Order parameter for GroupAttribute#115
Preliy wants to merge 2 commits into
annulusgames:mainfrom
Preliy:group_order

Conversation

@Preliy

@Preliy Preliy commented May 18, 2025

Copy link
Copy Markdown

This PR introduces an optional int order parameter to the existing GroupAttribute, allowing inspector fields to be grouped and drawn in a defined sequence. Previously, reflection order could lead to unpredictable group ordering when fields are spread across base and derived classes.

Usage Example:

public class GroupOrderTest : MonoBehaviour
{
    [Group("Group3", 30)]
    [SerializeField]
    private float _valueFloatGroup3;
    
    [Group("Group3", 30)]
    [SerializeField]
    private string _valueStringGroup3;
    
    [Group("Group2", 20)]
    [SerializeField]
    private string _valueStringGroup2;
    
    [Group("Group1", 10)]
    [SerializeField]
    private float _valueFloatGroup1;
    
    [Group("Group1", 10)]
    [SerializeField]
    private string _valueStringGroup1;
    
    [Group("Group2", 20)]
    [SerializeField]
    private float _valueFloatGroup2;
    
    [Group("Group3" , 30)]
    [SerializeField]
    private bool _valueBoolGroup3;
    
    [Group("Group2", 20)]
    [SerializeField]
    private bool _valueBoolGroup2;
    
    [Group("Group1", 10)]
    [SerializeField]
    private bool _valueBoolGroup1;
}

Inspector:
image

@paq

paq commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the contribution, and I’m sorry this PR has been left without a review for so long.
I’ve recently joined as a maintainer and am reviewing the existing pull requests as part of restarting maintenance of the project.

The underlying issue addressed here is valid: group ordering should be deterministic and should not depend on reflection discovery order.

However, I don’t think adding an order parameter to the group attributes is the right API design. Alchemy already has [Order] for controlling Inspector ordering, and introducing a separate ordering mechanism for groups would create overlapping concepts and expand the public group API unnecessarily.

If you’re still interested in contributing this improvement, would you be willing to revise the implementation to use the existing [Order] attribute instead? For example:

[Group("Group1"), Order(10)]
[SerializeField]
float value;

This would solve the original ordering problem while keeping a single, consistent API for ordering Inspector elements.

Thanks again for identifying the problem and contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants