-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Components as entities (v2) #24728
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
Open
Trashtalk217
wants to merge
17
commits into
bevyengine:main
Choose a base branch
from
Trashtalk217:components-as-entities-alt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+658
−878
Open
Components as entities (v2) #24728
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
22e24fb
make ComponentId use Entity
Trashtalk217 96d54c9
removed ResourceEntities
Trashtalk217 45ff041
fix world_serialization tests
Trashtalk217 5e9d8fa
add PR number
Trashtalk217 16f2b9e
fix bevy_remote
Trashtalk217 c6d1670
fix dynamic example
Trashtalk217 a7d5879
fix doc test
Trashtalk217 eed38d9
fix bevy_settings test
Trashtalk217 a6d7ea3
forgot to remove a println!
Trashtalk217 9056e8a
fix benchmark
Trashtalk217 8430a66
Merge branch 'main' of https://github.com/bevyengine/bevy into compon…
Trashtalk217 63cd089
improved migration guide, added iter_registered_ids, addressed review
Trashtalk217 50ec233
markdown error
Trashtalk217 731b5e6
addressed most of chescocks review
Trashtalk217 05c6204
clippy
Trashtalk217 cc02f45
address review pt 2
Trashtalk217 958d2bb
fix test
Trashtalk217 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
_release-content/migration-guides/components-as-entities.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| title: "Components as Entities" | ||
| pull_requests: [24728] | ||
| --- | ||
|
|
||
| - `ComponentId::new` now takes `Entity` as an argument instead of `usize`. For debugging, you can use `ComponentId::from_u32`. | ||
| - `ComponentId::index` was removed in favor of implementing `ContainsEntity`, call `ComponentId::entity` to get the underlying entity. | ||
| - `ComponentIdSet` is now an `EntityEquivalentHashSet` instead of a `FixedBitSet`. This means that methods like `union_with` no longer work, use `bitor_assign` instead. | ||
| - `ComponentIds` has been removed. Instead of `ComponentIds`, `ComponentsRegistrator::new` now takes `EntityAllocator`, while `ComponentsQueuedRegistrator::new` now takes `RemoteAllocator`. | ||
| - `Access` and `EcsAccessType` no longer derive `Hash`. | ||
| - `ResourceEntities` was removed. The following methods have been removed with it: `World::resource_entities`, `EntityWorldMut::resource_entities`, `UnsafeWorldCell::resource_entities`. If you need the entity linked with a `ComponentId`, simply call `component_id.entity()`. | ||
| - Despawning a resource entity has been upgraded from a `warn!` to a `panic!`, moreover, removing `IsResource` from a resource entity also panics. | ||
|
|
||
| In 0.19, you could attach components to a resource by simply calling `world.spawn((Res1, Comp1, Comp2))`. In 0.20, this no longer works as `Res1` needs to be on the resource entity allocated by `world.register_component<Res1>()`. In 0.20, adding components looks as follows: | ||
|
|
||
| ```rust | ||
| let entity = world.register_component::<R>().entity(); | ||
| world.spawn_at(entity, (Res1, Comp1, Comp2)); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| //! Constant components included in every world. | ||
|
|
||
| /// `usize` for the [`Add`](crate::lifecycle::Add) component used in lifecycle observers. | ||
| pub const ADD: usize = 0; | ||
| /// `usize` for the [`Insert`](crate::lifecycle::Insert) component used in lifecycle observers. | ||
| pub const INSERT: usize = 1; | ||
| /// `usize` for the [`Discard`](crate::lifecycle::Discard) component used in lifecycle observers. | ||
| pub const DISCARD: usize = 2; | ||
| /// `usize` for the [`Remove`](crate::lifecycle::Remove) component used in lifecycle observers. | ||
| pub const REMOVE: usize = 3; | ||
| /// `usize` for [`Despawn`](crate::lifecycle::Despawn) component used in lifecycle observers. | ||
| pub const DESPAWN: usize = 4; | ||
| /// `usize` of the [`IsResource`](crate::resource::IsResource) component used to mark entities with resources. | ||
| pub const IS_RESOURCE: usize = 5; | ||
| /// `u32` for the [`Add`](crate::lifecycle::Add) component used in lifecycle observers. | ||
| pub const ADD: u32 = 0; | ||
| /// `u32` for the [`Insert`](crate::lifecycle::Insert) component used in lifecycle observers. | ||
| pub const INSERT: u32 = 1; | ||
| /// `u32` for the [`Discard`](crate::lifecycle::Discard) component used in lifecycle observers. | ||
| pub const DISCARD: u32 = 2; | ||
| /// `u32` for the [`Remove`](crate::lifecycle::Remove) component used in lifecycle observers. | ||
| pub const REMOVE: u32 = 3; | ||
| /// `u32` for [`Despawn`](crate::lifecycle::Despawn) component used in lifecycle observers. | ||
| pub const DESPAWN: u32 = 4; | ||
| /// `u32` of the [`IsResource`](crate::resource::IsResource) component used to mark entities with resources. | ||
| pub const IS_RESOURCE: u32 = 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is
clear_entities()completely unusable now? Any resource that had been spawned can never be created again, right? Should we just remove it completely?And, should this bench still despawn the entities that are spawned by
add_archetypes? We could presumably add a marker component to identify them.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.
It is completely unusable except for the one niche use case of benchmarking. In the case of
add_archetypesI was able to maintain the behaviour by addinge.despawn()withinadd_archetypes.I do not want to redo a bunch of benchmarks right now, but I agree we should remove (or alter)
clear_entitiesin the future.