Skip to content

Entity grouping code for entity inspector - #25010

Open
alice-i-cecile wants to merge 6 commits into
bevyengine:mainfrom
alice-i-cecile:entity_grouping
Open

Entity grouping code for entity inspector#25010
alice-i-cecile wants to merge 6 commits into
bevyengine:mainfrom
alice-i-cecile:entity_grouping

Conversation

@alice-i-cecile

@alice-i-cecile alice-i-cecile commented Jul 16, 2026

Copy link
Copy Markdown
Member

Objective

As part of #23013, we want to be able to order our list of entities in some sensible way, grouping and sorting them.

Solution

During prototyping in feathers_inspector, @Nilirad and I found that there were two helpful, straightforward approaches: hierachical grouping and relying on archetype similarity, so similar entities are presented together.

The code from there has been adapted and mildly cleaned up, and is offered unto the Bevy review gods for incremental review, rather than giving y'all a 20k line diff.

Testing

See tests module :) I've added some extra to cover the archetype grouping strategy, which was untested.

This module is very algorithmic with nice invariants, so testing was quite pleasant!

Add more tests

Use faster EntityHashSet

Leave a PERF note about entity set iterator
@alice-i-cecile alice-i-cecile added this to the 0.20 milestone Jul 16, 2026
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Dev-Tools Tools used to debug Bevy applications. X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 16, 2026
@kazunariueda0831-blip

This comment was marked as spam.

@github-actions

Copy link
Copy Markdown
Contributor

You added a new example but didn't add metadata for it. Please update the root Cargo.toml file.

@viridia

viridia commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

This is one of those things that is subjective, I can think of other possible orderings that an alternate, third-party entity browser might want - like a fixed order (cameras first, then lights, etc.), or "search relevance". Each implementation of "list entities widget" will likely have its own opinions about how entities should be grouped. That means that this code isn't universal or fundamental IMHO.

I don't have a problem with the algorithms specifically.

@alice-i-cecile

Copy link
Copy Markdown
Member Author

I agree! But I'd like to get something in now, and add more variants, so we can ship a better organization than "by entity ID" in the first-party inspector tools. If you would like me to make this more extensible; just let me know and I can do some sort of trait based design.

Comment on lines +40 to +50
/// Generates an [`EntityGrouping`] based on the components of the provided entities.
pub fn generate(
world: &World,
entities: impl IntoIterator<Item = Entity>,
strategy: GroupingStrategy,
) -> Self {
match strategy {
GroupingStrategy::Hierarchy => hierarchy_group(world, entities),
GroupingStrategy::ArchetypeSimilarity => archetype_group(world, entities),
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels strange to me that we have to choose between grouping by hierarchy and by archetype similarity. i would imagine that instead we have a hierarchy of entities based on a relationship (be it ChildOf or a custom one), and each set of children is then grouped by archetype similarity

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this ordering would primarily be used for root entities, which have no relationship between them. In a typical scene there can be a large number of these, so some sort of grouping can be helpful.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, ideally you'd do a first pass of archetype similarity for root entities, and then a second for hierarchy within them :) I can make that more explicit, via either code or docs if you'd like?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think a utility function to do that would be handy, yes!

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

Labels

A-Dev-Tools Tools used to debug Bevy applications. C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants