Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
042337f
add back all changes
Trashtalk217 Jul 10, 2025
47c20a5
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Jul 10, 2025
64eac9a
cargo fmt
Trashtalk217 Jul 10, 2025
956c1a6
cargo clippy
Trashtalk217 Jul 10, 2025
073df4b
add entities with resources, auto disabled IsResource
Trashtalk217 Jul 12, 2025
6c8281d
fixed and tests
Trashtalk217 Jul 12, 2025
f9dc9f1
fixed more tests
Trashtalk217 Jul 12, 2025
07723ac
fixed moore tests
Trashtalk217 Jul 12, 2025
1ba7af2
fix ci
Trashtalk217 Jul 12, 2025
b89c042
fix mooore tests (benches)
Trashtalk217 Jul 12, 2025
9b33933
fix docs
Trashtalk217 Jul 12, 2025
c7b4f1d
add migration guide
Trashtalk217 Jul 12, 2025
96aef45
fixed spelling errors to prove I'm not AI
Trashtalk217 Jul 12, 2025
e3ccd1b
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Jul 12, 2025
5758134
addressed comments
Trashtalk217 Jul 13, 2025
9824c3a
testing robustness
Trashtalk217 Jul 14, 2025
9acf43f
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Jul 14, 2025
da1d203
merge upstream
Trashtalk217 Jul 23, 2025
4d4e914
cleanup
Trashtalk217 Jul 23, 2025
78a0672
fix more stuff
Trashtalk217 Jul 23, 2025
4a2416d
update migration guides
Trashtalk217 Jul 24, 2025
3942c56
spelling
Trashtalk217 Jul 24, 2025
511e0b9
update resource macros to implement Component
Trashtalk217 Jul 24, 2025
d4c98eb
fix tests
Trashtalk217 Jul 24, 2025
724a4c4
merge
Trashtalk217 Aug 22, 2025
f442ff6
fix imports
Trashtalk217 Aug 22, 2025
acb539e
second attempt at fixing a test
Trashtalk217 Aug 22, 2025
a0d76c3
merge
Trashtalk217 Aug 30, 2025
c99df9c
Merge branch 'resource_entity_lookup' of github.com:trashtalk217/bevy…
Trashtalk217 Aug 30, 2025
12383a3
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Sep 2, 2025
34570e8
Merge branch 'resource_entity_lookup' into resource-as-components
Trashtalk217 Sep 2, 2025
f43905d
removed send resources from Storages
Trashtalk217 Sep 8, 2025
36e8191
fixed more tests
Trashtalk217 Sep 8, 2025
d1b9b56
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Sep 8, 2025
bfb2829
Merge branch 'resource_entity_lookup' into resource-as-components
Trashtalk217 Sep 8, 2025
011b068
cleanup
Trashtalk217 Sep 8, 2025
a12ec78
partly fixed bevy_scene
Trashtalk217 Sep 12, 2025
2261f8b
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Sep 14, 2025
7f224be
address comments
Trashtalk217 Sep 14, 2025
4b0c77b
Merge branch 'resource_entity_lookup' into resource-as-components
Trashtalk217 Sep 14, 2025
6fdf25e
fixed try_resource_scope in part
Trashtalk217 Sep 14, 2025
2b1a5b5
fixed require() statement for AmbientLight
Trashtalk217 Sep 17, 2025
e8c67cc
change location of resource_entities
Trashtalk217 Sep 18, 2025
a01dc7d
changed scene serialization
Trashtalk217 Sep 18, 2025
9aecdf3
removed ResourceEntity, redid bevy_scene, require ReflectComponent for
Trashtalk217 Sep 22, 2025
3ddf8bf
fixed final tests
Trashtalk217 Sep 23, 2025
f0e973a
cargo clippy fixes
Trashtalk217 Sep 23, 2025
02c2b5f
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Sep 23, 2025
8c1c818
removed dead code
Trashtalk217 Sep 23, 2025
1383efd
typo
Trashtalk217 Sep 23, 2025
2f9990a
more clippy
Trashtalk217 Sep 23, 2025
678da53
fixed get_resources_mut and unsoundness Res and ResMut
Trashtalk217 Sep 25, 2025
67810f4
updated docs
Trashtalk217 Sep 25, 2025
af03cec
improve docs and name
Trashtalk217 Sep 25, 2025
25b49d0
cargo clippy
Trashtalk217 Sep 25, 2025
1117cfa
typos
Trashtalk217 Sep 25, 2025
e3b12c2
fixed bevy_render bug
Trashtalk217 Sep 25, 2025
33bd43d
fixed bevy_remove
Trashtalk217 Sep 25, 2025
18c7664
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Sep 25, 2025
c75da2c
added ReflectComponent to debug_overlay
Trashtalk217 Sep 25, 2025
0e4d5c2
fixed docs
Trashtalk217 Sep 25, 2025
0eef31b
addressed comments
Trashtalk217 Sep 26, 2025
e68d5c2
fixed a bug with try_resource_scope
Trashtalk217 Sep 27, 2025
44c526b
typos
Trashtalk217 Sep 27, 2025
fb01522
clippy
Trashtalk217 Sep 27, 2025
d70a178
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Sep 27, 2025
8afc908
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Oct 17, 2025
44927a5
remove all unnecessary resourceComponent
Trashtalk217 Oct 24, 2025
e953fa1
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Oct 26, 2025
4cbdaa5
remove entity_ref
Trashtalk217 Oct 26, 2025
2ec2182
further cleanup
Trashtalk217 Oct 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/bevy_ecs/macros/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use syn::{
};

pub fn derive_resource(input: TokenStream) -> TokenStream {
// The resource derive *also* implements the Component trait
// We generate the Component implementation first, then add the Resource implementation,
// so then we can pick up all of the attributes from the Component derive
let component_derive_token_stream = derive_component(input.clone());
Comment on lines +17 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really prefer not to derive Component for resources. Can't we just have a struct ResourceComponent<R: Resource>(R); instead?

Also, I'm not sure why the order matterrs here, it seems irrelevant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of the motivation for resources-as-components is being able to use tools like Observers and ComponentHooks for resources as well. For this, resources need to derive Component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why the migration guide mentions them being marked as internal then.


let mut ast = parse_macro_input!(input as DeriveInput);
let bevy_ecs_path: Path = crate::bevy_ecs_path();

Expand All @@ -40,10 +45,15 @@ pub fn derive_resource(input: TokenStream) -> TokenStream {
let struct_name = &ast.ident;
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();

TokenStream::from(quote! {
let resource_impl_token_stream = TokenStream::from(quote! {
impl #impl_generics #bevy_ecs_path::resource::Resource for #struct_name #type_generics #where_clause {
}
})
});

resource_impl_token_stream
.into_iter()
.chain(component_derive_token_stream)
.collect()
}

/// Component derive syntax is documented on both the macro and the trait.
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,10 @@ pub fn derive_message(input: TokenStream) -> TokenStream {
}

/// Implement the `Resource` trait.
#[proc_macro_derive(Resource)]
#[proc_macro_derive(
Resource,
attributes(component, require, relationship, relationship_target, entities)
)]
pub fn derive_resource(input: TokenStream) -> TokenStream {
component::derive_resource(input)
}
Expand Down Expand Up @@ -677,7 +680,7 @@ pub fn derive_resource(input: TokenStream) -> TokenStream {
/// #[component(hook_name = function)]
/// struct MyComponent;
/// ```
/// where `hook_name` is `on_add`, `on_insert`, `on_replace` or `on_remove`;
/// where `hook_name` is `on_add`, `on_insert`, `on_replace` or `on_remove`;
/// `function` can be either a path, e.g. `some_function::<Self>`,
/// or a function call that returns a function that can be turned into
/// a `ComponentHook`, e.g. `get_closure("Hi!")`.
Expand Down
7 changes: 3 additions & 4 deletions crates/bevy_ecs/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ impl ComponentDescriptor {
pub struct Components {
pub(super) components: Vec<Option<ComponentInfo>>,
pub(super) indices: TypeIdMap<ComponentId>,
pub(super) resource_indices: TypeIdMap<ComponentId>,
// This is kept internal and local to verify that no deadlocks can occor.
pub(super) queued: bevy_platform::sync::RwLock<QueuedComponents>,
}
Expand Down Expand Up @@ -602,7 +601,7 @@ impl Components {
/// Type-erased equivalent of [`Components::valid_resource_id()`].
#[inline]
pub fn get_valid_resource_id(&self, type_id: TypeId) -> Option<ComponentId> {
self.resource_indices.get(&type_id).copied()
self.indices.get(&type_id).copied()
}

/// Returns the [`ComponentId`] of the given [`Resource`] type `T` if it is fully registered.
Expand Down Expand Up @@ -680,7 +679,7 @@ impl Components {
/// Type-erased equivalent of [`Components::resource_id()`].
#[inline]
pub fn get_resource_id(&self, type_id: TypeId) -> Option<ComponentId> {
self.resource_indices.get(&type_id).copied().or_else(|| {
self.indices.get(&type_id).copied().or_else(|| {
self.queued
.read()
.unwrap_or_else(PoisonError::into_inner)
Expand Down Expand Up @@ -738,7 +737,7 @@ impl Components {
unsafe {
self.register_component_inner(component_id, descriptor);
}
let prev = self.resource_indices.insert(type_id, component_id);
let prev = self.indices.insert(type_id, component_id);
debug_assert!(prev.is_none());
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/component/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl<'w> ComponentsRegistrator<'w> {
type_id: TypeId,
descriptor: impl FnOnce() -> ComponentDescriptor,
) -> ComponentId {
if let Some(id) = self.resource_indices.get(&type_id) {
if let Some(id) = self.indices.get(&type_id) {
return *id;
}

Expand Down
9 changes: 7 additions & 2 deletions crates/bevy_ecs/src/entity_disabling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ use smallvec::SmallVec;

#[cfg(feature = "bevy_reflect")]
use {
crate::reflect::ReflectComponent, bevy_reflect::std_traits::ReflectDefault,
crate::reflect::{ReflectComponent, ReflectResource},
bevy_reflect::std_traits::ReflectDefault,
bevy_reflect::Reflect,
};

Expand Down Expand Up @@ -166,7 +167,11 @@ pub struct Disabled;
/// Think carefully about whether you need to use a new disabling component,
/// and clearly communicate their presence in any libraries you publish.
#[derive(Resource, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
#[cfg_attr(
feature = "bevy_reflect",
derive(bevy_reflect::Reflect),
reflect(Resource)
)]
pub struct DefaultQueryFilters {
// We only expect a few components per application to act as disabling components, so we use a SmallVec here
// to avoid heap allocation in most cases.
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,8 +1555,8 @@ mod tests {
let mut world_a = World::new();
let world_b = World::new();
let mut query = world_a.query::<&A>();
let _ = query.get(&world_a, Entity::from_raw_u32(0).unwrap());
let _ = query.get(&world_b, Entity::from_raw_u32(0).unwrap());
let _ = query.get(&world_a, Entity::from_raw_u32(10_000).unwrap());
let _ = query.get(&world_b, Entity::from_raw_u32(10_000).unwrap());
}

#[test]
Expand Down Expand Up @@ -1796,7 +1796,7 @@ mod tests {
fn try_insert_batch() {
let mut world = World::default();
let e0 = world.spawn(A(0)).id();
let e1 = Entity::from_raw_u32(1).unwrap();
let e1 = Entity::from_raw_u32(10_000).unwrap();

let values = vec![(e0, (A(1), B(0))), (e1, (A(0), B(1)))];

Expand All @@ -1820,7 +1820,7 @@ mod tests {
fn try_insert_batch_if_new() {
let mut world = World::default();
let e0 = world.spawn(A(0)).id();
let e1 = Entity::from_raw_u32(1).unwrap();
let e1 = Entity::from_raw_u32(10_000).unwrap();

let values = vec![(e0, (A(1), B(0))), (e1, (A(0), B(1)))];

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ mod tests {
let mut query = world.query::<NameOrEntity>();
let d1 = query.get(&world, e1).unwrap();
// NameOrEntity Display for entities without a Name should be {index}v{generation}
assert_eq!(d1.to_string(), "0v0");
assert_eq!(d1.to_string(), "1v0");
let d2 = query.get(&world, e2).unwrap();
// NameOrEntity Display for entities with a Name should be the Name
assert_eq!(d2.to_string(), "MyName");
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/reflect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use component::{ReflectComponent, ReflectComponentFns};
pub use entity_commands::ReflectCommandExt;
pub use from_world::{ReflectFromWorld, ReflectFromWorldFns};
pub use map_entities::ReflectMapEntities;
pub use resource::{ReflectResource, ReflectResourceFns};
pub use resource::ReflectResource;

/// A [`Resource`] storing [`TypeRegistry`] for
/// type registrations relevant to a whole app.
Expand Down
Loading
Loading