-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add an example teaching users about custom relationships #17443
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
Conversation
Co-authored-by: Joona Aalto <[email protected]>
Co-authored-by: Joona Aalto <[email protected]>
Co-authored-by: MinerSebas <[email protected]>
…relations-example
Co-authored-by: Kristoffer Søholm <[email protected]>
// 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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this 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!
I have no idea what's going on with CI here: I can't reproduce the failures locally or on |
…17443) # Objective After bevyengine#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. --------- Co-authored-by: Joona Aalto <[email protected]> Co-authored-by: MinerSebas <[email protected]> Co-authored-by: Kristoffer Søholm <[email protected]>
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
AddRelationship
andRelationshipTarget
to the prelude: the trait methods are really helpful here.Testing
cargo run --example relationships
Notes to reviewers
App
, I've decide to useWorld::run_system_once
+ system functions defined inside ofmain
to do something closer to literate programming.