Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement better EntityPath #12892

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Multirious
Copy link
Contributor

@Multirious Multirious commented Apr 6, 2024

Motivation

Previously there's EntityPath in bevy_animation which is just a Vec<Name> to refer to an entity for animation.
I was trying to work on something else and thought that EntityPath could actually its own thing for general usages in Bevy. Inspired by Godot's NodePath.

  • This could increase hierarchy ergonomics and useful when Bevy's editor arrive, as it can be an intuitive and simple way to find entities in the hierarchy.
    • UI is heavily hierarchical and would be one step simpler with EntityPath. You can refer to them by path (like in Godot!)
  • EntityPath could be used when you don't know the entity id ahead of time.
    • There's other solution such as marker components but marker is in the world context which can collide when there are multiple scenes, while EntityPath can be relative to the entity and the scene.

I want to implement the Godot's unique name feature too but seems like this should be a separated PR.

I'm working on this in another personal repository to keep my RA sane and also in case this is not merge and can be a mod crate.

Objective

Adds EntityPath that will operates on the Name component with additional enum variant.

EntityPath can:

  • Find a child via Name component.
  • Find the parent.
  • Find an entity relative to scene's root. Should be in alternate PR/crate
  • Find an entity relative to world's root (or an entity that doesn't have a parent).
  • Add system param for path

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-Core Common functionality for all bevy apps A-Hierarchy Parent-child entity hierarchies X-Controversial There is active debate or serious implications around merging this PR labels Apr 8, 2024
@cart
Copy link
Member

cart commented Apr 9, 2024

As a heads up, I'm working on "new scene system" stuff right now and I'd very much like to support EntityPath scenarios like this:

#[derive(Component, Construct)]
struct SomeComponent {
  #[construct]
  entity: Entity,
}

fn spawn() -> Bsn {
  bsn! {
    SomeComponent { entity: @"../../SomeEntityName" }
  }
}

@Multirious
Copy link
Contributor Author

Multirious commented Apr 10, 2024

I think I'd like to separate the "path from scene-root" stuff from this pull request. This would require additional resources or component storing scene metadata/context (Also working on it in another crate). Other stuff is working just fine now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Core Common functionality for all bevy apps A-Hierarchy Parent-child entity hierarchies C-Enhancement A new feature X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants