Repository navigation
Conversation
Updates the bsn example to show how a EntityTemplate can be passed around functions and store in a component for later use
Clearing up the text in the "Named Entity Reference" section in bevy_scene docs and adding a few more examples on how this can be used
Co-authored-by: Martín Maita <47983254+mnmaita@users.noreply.github.com>
| //! ```ignore | ||
| //! bsn! { | ||
| //! #Root | ||
| //! Reference(#Child) |
There was a problem hiding this comment.
Can you say more about why this was swapped? I think that showing the basic form first is a bit clearer pedagogically.
There was a problem hiding this comment.
The basic form is showed in the example above (lines 161). The text above this example comments about that, and says that Ancestors can access their descendants but it was never showed.
| //! Using `#Name` as a value in [`bsn!`] will result in an [`EntityTemplate`], which is a [`Template`] that resolves to an [`Entity`] | ||
| //! [`Component`]s with [`Entity`] fields should generally derive [`FromTemplate`], because [`Entity`] uses [`FromTemplate`] to map to [`EntityTemplate`]. | ||
| //! | ||
| //! ```rust, ignore |
There was a problem hiding this comment.
We should avoid ignoring doc tests when possible to improve robustness when refactoring. It looks like that's the style here, but you can make them compile using # to hide the import lines.
Not blocking though.
There was a problem hiding this comment.
I'll keep it in mind for future doc work. I blindly followed the style in this page. The igonore is removed from my code. I tried to remove from the rest of the main page, but rustdoc --test bevy_scene/src/lib.rs included erroneous code from all the crate documentation and I got overwhelmed lol.
| BackgroundColor(Color::srgb(0.15, 0.15, 0.15)) | ||
| on(|event: On<PointerPress>, q_reference: Query<&Reference> |{ | ||
| let ui_holder = q_reference.get(event.entity).expect("We are sure it exists"); | ||
| println!("I have a reference to this entity => {:#?}", ui_holder.0); |
There was a problem hiding this comment.
This language is a bit confusing: it's not a reference in the Rust sense.
There was a problem hiding this comment.
My idea was to keep the language of the docs, were I use Reference as the component to hold the Entity, and this just came together. I agree it could be somewhat confusing. I'll refactor it.
There was a problem hiding this comment.
I changed to RootUi, it should be more descriptive and shows a potential use case =)
zincdev0
left a comment
There was a problem hiding this comment.
Looks good, I left some (albeit pedantic) notes in the example.
|
|
||
| fn ui() -> impl Scene { | ||
| bsn! { | ||
| #MainUI |
There was a problem hiding this comment.
The naming difference between #MainUI and struct RootUi, which represent the same thing, could be confusing.
| fn button(label: &str, root_entity: EntityTemplate) -> impl Scene { | ||
| bsn! { | ||
| Button | ||
| RootUi( root_entity ) |
There was a problem hiding this comment.
The whitespace around root_entity would be removed by rustfmt, if this wasn't a bsn! block.
Objective
Improve clarity around
Named Entity References, how to pass theEntityTemplatearound and storing the entity in a ComponentSolution
Named Entity Referenceinbevy_scene docs, making the text clearer.EntityTemplategenerated, how to pass it to functions and how to store the entity generated in a componentTesting
Duplicate of #26146 because I messed up :)