-
Notifications
You must be signed in to change notification settings - Fork 12
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 world to scene hook #11
Conversation
When I am at it, here's an example from original bevy issue bevyengine/bevy#4933 that is made possible with this change, it is also quite similar to the code I am using: Original code from issue: commands.spawn_bundle(SceneBundle {
scene: asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"),
hook: SceneHook::new(|entity_ref, entity_commands| {
if let Some(mesh) = entity_ref.get::<Mesh>() {
// Entity have mesh, let's assign collision:
entity_commands.insert(RigidBody::Fixed);
entity_commands.insert(Collider::from_bevy_mesh(mesh));
} else if let Some(name) = entity_ref.get::<Name>() {
// Can insert some components based on name
}
}),
..Default::default()
}); Current possible code with commands.spawn(HookedSceneBundle {
scene: SceneBundle {
scene: asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"),
..Default::default()
},
hook: SceneHook::new(|entity, cmds, world| {
if let Some(mesh_handle) = entity.get::<Handle<Mesh>>() {
let meshes = world.resource::<Assets<Mesh>>();
let mesh = meshes.get(mesh_handle);
// Entity have mesh, let's assign collision:
cmds.insert(RigidBody::Fixed);
cmds.insert(Collider::from_bevy_mesh(mesh));
} else if let Some(name) = entity.get::<Name>() {
// Can insert some components based on name
}
})
}); |
4844054
to
67b47aa
Compare
Yep, the reloadable hook is indeed the secret super-powered version of the basic hook. It's not very discoverable, and that's my fault, you are not the first one to discover it after solving something the reloadable hook already solves. I'm not interested in merging this in the immediate future because it's a breaking change. A few questions:
|
Sounds reasonable.
I do like the simplicity of
I think mentioning it in crate-level doc would help me. The crate level doc now states:
Just mentioning the
|
Few ideas for making the hook reloadable but simple:
|
Hello, I integrated your suggestion wrt to |
Adds read only access to world when running scene hook.
My motivation for this change was, that i needed to access Meshes to create colliders, not unlike the original discussion that seems to lead to the creation of
bevy-scene-hook
: bevyengine/bevy#4933.Previous version of bevy had access to world through
EntityRef
, documented here in migration guide: https://bevyengine.org/learn/migration-guides/0.11-0.12/#allow-disjoint-mutable-world-access-via-entitymut, the suggestion there seems to be to add system param to accessWorld
which this PR does.When I made this PR, I looked into all of the source code of
bevy-scene-hook
to replace all occurences ofSceneHook::new
to addworld
parameter and found that there is another reloadable hook which does haveWorld
parameter and realized I can use that instead of addingWorld
parameter toSceneHook
and since I've already made the changes, the least I could do is to make a PR, so there is at least parity between the two hooks andSceneHook
can be used if someone does not want the reload functionality.Thanks for making this crate, it is an elegant solution with so little code.