-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 demonstrating how to use default query filtering and entity cloning to create a prefab system #17769
base: main
Are you sure you want to change the base?
Conversation
video that shows the flickering (and longer non-rendering meshes) screenshot-2025-02-09-at-17.41.51.mp4 |
@@ -320,6 +320,7 @@ Example | Description | |||
[Observers](../examples/ecs/observers.rs) | Demonstrates observers that react to events (both built-in life-cycle events and custom events) | |||
[One Shot Systems](../examples/ecs/one_shot_systems.rs) | Shows how to flexibly run systems without scheduling them | |||
[Parallel Query](../examples/ecs/parallel_query.rs) | Illustrates parallel queries with `ParallelIterator` | |||
[Prefabs](../examples/ecs/prefabs.rs) | Demonstrates how to load, store and clone template entity collections |
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 think this deserves a qualifier or a different more specific name less loaded with context. People will see this name and think "this is the Bevy prefab system", which has implications like "an asset format", "inheritance", etc.
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.
Good call; I definitely think that's the right call for the current stage of maturity.
Objective
Bevy users have long wished for tools for working with a "prefab"-style workflows: #10949, #3877, #2565, #1446...
The core idea is pretty simple: define an "object" (made up of some collection of entities) that we can save, instantiated, into the world, and then clone and modify them as needed.
Solution
Instead of creating a first-class solution, I've instead chosen to add an example demonstrating how this pattern can be achieved quite simply with a combination of default query filters and recursive entity cloning.
This is useful for teaching users how to create their own prefab-flavored solution, and gives us time to iterate on the ideal solution.
Long-term, I think that Bevy would be well-served by making a first party prefab workflow, complete with a standardized state-powered asset loading solution. It's nice to be able to teach this pattern directly to new users, and more importantly, it allows us to view and building tooling around prefabs for e.g. a GUI-based level editor.
But Bevy itself is a poor place to prove out the architectural details for this: we aren't actually testing it in a large game project, and so the solution isn't subject to the appropriate pressures. Once the community has developed a robust solution, we should upstream it (likely as a standalone crate) and update this example!
To do
This PR is not yet complete!
Before it's merged, we need to:
It might also be nice to:
Like always, feel free to PR to my branch if you want to fix these.
Testing
cargo run --example prefabs
Showcase