-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Added an init_bundle
method to World
#12573
Conversation
…d return a &[ComponentId]
crates/bevy_ecs/src/world/mod.rs
Outdated
let id = self | ||
.bundles | ||
.init_info::<B>(&mut self.components, &mut self.storages); | ||
self.bundles.get(id).unwrap().components() |
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.
self.bundles.get(id).unwrap().components() | |
// SAFETY: The bundle was just initialized. The bundle must still exist. | |
unsafe { self.bundles.get(id).debug_unwrap_unchecked().components() } |
We should be avoid panicking in the ECS when we know the invariants are satisfied. Ideally init_info
should return a &BundleInfo
to avoid the need for this, but that's out of the scope of the PR.
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.
I've changed it to unwrap_unchecked
, I couldn't find a debug_unwrap_unchecked
anywhere?
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.
DebugCheckedUnwrap is an extension trait we have inside bevy_ecs. It's identical but panics in debug mode if the Option isn't actually Some.
…his removes the chance of a panic
…ponent ids to give the end user more flexibility
Objective
Make it easy to get the ids of all the components in a bundle (and initialise any components not yet initialised). This is fairly similar to the
Bundle::get_component_ids()
method added in the observers PR however that will return none for any non-initialised components. This is exactly the API space covered byBundle::component_ids()
however that isn't possible to call outside ofbevy_ecs
as it requires&mut Components
and&mut Storages
.Solution
Added
World.init_bundle<B: Bundle>()
which similarly toinit_component
andinit_resource
, initialises all components in the bundle and returns a vector of their component ids.Changelog
Added the method
init_bundle
toWorld
as a counterpart toinit_component
andinit_resource
.