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

Add an example teaching users about custom relationships #17443

Merged
merged 23 commits into from
Jan 20, 2025

Conversation

alice-i-cecile
Copy link
Member

@alice-i-cecile alice-i-cecile commented Jan 19, 2025

Objective

After #17398, Bevy now has relations! We don't teach users how to make / work with these in the examples yet though, but we definitely should.

Solution

  • Add a simple abstract example that goes over defining, spawning, traversing and removing a custom relations.
  • Add Relationship and RelationshipTarget to the prelude: the trait methods are really helpful here.
    • this causes subtle ambiguities with method names and weird compiler errors. Not doing it here!
  • Clean up related documentation that I referenced when writing this example.

Testing

cargo run --example relationships

Notes to reviewers

  1. Yes, I know that the cycle detection code could be more efficient. I decided to reduce the caching to avoid distracting from the broader point of "here's how you traverse relationships".
  2. Instead of using an App, I've decide to use World::run_system_once + system functions defined inside of main to do something closer to literate programming.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 19, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Jan 19, 2025
examples/ecs/hierarchy.rs Outdated Show resolved Hide resolved
Co-authored-by: Joona Aalto <[email protected]>
examples/ecs/relationships.rs Outdated Show resolved Hide resolved
// even though the entity itself is not yet instantiated in the world.
// This works because Commands will reserve the entity ID before actually spawning the entity,
// through the use of atomic counters.
let alice = commands.spawn(Name::new("Alice")).id();
Copy link
Contributor

Choose a reason for hiding this comment

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

Crazy question, but where is 'Name' coming from?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bevy_core component! It's quite nice!

Copy link
Contributor

@Carter0 Carter0 left a comment

Choose a reason for hiding this comment

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

Minor comments, but overall I think It looks good!

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 20, 2025
@alice-i-cecile
Copy link
Member Author

I have no idea what's going on with CI here: I can't reproduce the failures locally or on main.

@alice-i-cecile alice-i-cecile added S-Needs-Help The author needs help finishing this PR. and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jan 20, 2025
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Help The author needs help finishing this PR. labels Jan 20, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 20, 2025
Merged via the queue into bevyengine:main with commit b34833f Jan 20, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants