Skip to content
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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

alice-i-cecile
Copy link
Member

@alice-i-cecile alice-i-cecile commented Feb 10, 2025

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:

  • add instruction text
  • load more than one model, and actually make use of that hash map
  • define and use an asset loading state (please discuss!)
  • somehow extract the asset path from the SceneInstanceReady event and cache that

Like always, feel free to PR to my branch if you want to fix these.

Testing

cargo run --example prefabs

Showcase

image

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples S-Blocked This cannot move forward until something else changes X-Controversial There is active debate or serious implications around merging this PR S-Needs-Help The author needs help finishing this PR. labels Feb 10, 2025
@alice-i-cecile alice-i-cecile requested a review from cart February 10, 2025 01:05
@ChristopherBiscardi
Copy link
Contributor

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
Copy link
Member

@cart cart Feb 10, 2025

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples S-Blocked This cannot move forward until something else changes S-Needs-Help The author needs help finishing this PR. X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants