Skip to content
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
114 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
ea36fec
more cleanup
Trashtalk217 Oct 26, 2025
1203662
more more cleanup
Trashtalk217 Oct 26, 2025
e751f15
removed a test and made IsResource automatically disabled (temporary)
Trashtalk217 Oct 26, 2025
2fa538e
rewrite resource component derive
Trashtalk217 Oct 26, 2025
740752d
change the hooks to be public under the Resource trait
Trashtalk217 Oct 26, 2025
737f04c
fixed compile problems, goto v2 implementation with hooks
Trashtalk217 Oct 26, 2025
8a1727b
deprecate dyanamic (send) resources
Trashtalk217 Oct 27, 2025
ff0e195
made ReflectResource deref to ReflectComponent
Trashtalk217 Oct 27, 2025
c9f7ec5
made resource entity stable, fixed bevy_scene
Trashtalk217 Oct 27, 2025
86962a8
fixed bevy_remote, added logging to hooks
Trashtalk217 Oct 27, 2025
3989f2e
remove pointless printing
Trashtalk217 Oct 27, 2025
d7d647e
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Oct 28, 2025
6ceed0d
fixed ci
Trashtalk217 Oct 28, 2025
b2b2248
fix ci some more
Trashtalk217 Oct 28, 2025
5028619
updated example asset
Trashtalk217 Oct 28, 2025
039cd0b
fix ci some more
Trashtalk217 Oct 28, 2025
1014aad
fix ci some more
Trashtalk217 Oct 28, 2025
9fd6129
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Oct 29, 2025
485c03a
revert to previous Res/ResMut implementation
Trashtalk217 Oct 30, 2025
8c67aa3
change doc comments
Trashtalk217 Oct 30, 2025
fe921d2
revert a weird bevy_render thing
Trashtalk217 Oct 30, 2025
75069d8
revert bevy_scene changes
Trashtalk217 Oct 30, 2025
da3f903
space
Trashtalk217 Oct 30, 2025
2453314
remove dead code
Trashtalk217 Oct 30, 2025
c9c0f95
cargo fmt
Trashtalk217 Oct 30, 2025
a4234fb
documentation
Trashtalk217 Oct 30, 2025
779b668
markdown fix
Trashtalk217 Oct 30, 2025
c919a69
fixed access bug
Trashtalk217 Nov 2, 2025
5438039
make is_resource not a dfq
Trashtalk217 Nov 2, 2025
4be1ccf
fix a broad query for animation conflicting with a resource
Trashtalk217 Nov 2, 2025
aa4d563
review comments
Trashtalk217 Nov 3, 2025
28ca0ac
fix
Trashtalk217 Nov 3, 2025
411a681
address review comments
Trashtalk217 Nov 7, 2025
a570cc3
forgot to make a change
Trashtalk217 Nov 7, 2025
e72f38e
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Nov 29, 2025
a5e9612
spelling
Trashtalk217 Nov 29, 2025
73a9293
fixed tests
Trashtalk217 Nov 29, 2025
a3bef34
oops forgot to save
Trashtalk217 Nov 29, 2025
57ca7d6
rename non-send resources to non-send data
Trashtalk217 Dec 4, 2025
3e36aba
misc changes based on review
Trashtalk217 Dec 4, 2025
31530f6
docs
Trashtalk217 Dec 4, 2025
89c5622
Merge branch 'main' of https://github.com/bevyengine/bevy into resour…
Trashtalk217 Dec 4, 2025
f3153da
reflect dependency
Trashtalk217 Dec 4, 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
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/scheduling/run_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn run_condition_no(criterion: &mut Criterion) {
group.finish();
}

#[derive(Component, Resource)]
#[derive(Resource)]
struct TestBool(pub bool);

pub fn run_condition_yes_with_query(criterion: &mut Criterion) {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_a11y/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ use bevy_ecs::{component::Component, message::Message, resource::Resource, sched

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

Expand Down
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());
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 @@ -25,10 +30,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 @@ -348,7 +348,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 @@ -588,7 +587,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 @@ -666,7 +665,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 @@ -724,7 +723,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 @@ -187,7 +188,11 @@ pub struct Internal;
/// 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
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mod tests {
};
use std::sync::Mutex;

#[derive(Component, Resource, Debug, PartialEq, Eq, Hash, Clone, Copy)]
#[derive(Resource, Debug, PartialEq, Eq, Hash, Clone, Copy)]
struct A(usize);
#[derive(Component, Debug, PartialEq, Eq, Hash, Clone, Copy)]
struct B(usize);
Expand Down Expand Up @@ -1553,8 +1553,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 @@ -1794,7 +1794,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 @@ -1818,7 +1818,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/message/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::{
};
#[cfg(feature = "bevy_reflect")]
use {
crate::reflect::ReflectResource,
crate::reflect::{ReflectComponent, ReflectResource},
bevy_reflect::{std_traits::ReflectDefault, Reflect},
};

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
66 changes: 65 additions & 1 deletion crates/bevy_ecs/src/resource.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
//! Resources are unique, singleton-like data types that can be accessed from systems and stored in the [`World`](crate::world::World).

use crate::component::Mutable;
use crate::entity_disabling::Internal;
use crate::prelude::Component;
use crate::prelude::ReflectComponent;
use bevy_reflect::prelude::ReflectDefault;
use bevy_reflect::Reflect;
// The derive macro for the `Resource` trait
pub use bevy_ecs_macros::Resource;

Expand Down Expand Up @@ -72,4 +78,62 @@ pub use bevy_ecs_macros::Resource;
label = "invalid `Resource`",
note = "consider annotating `{Self}` with `#[derive(Resource)]`"
)]
pub trait Resource: Send + Sync + 'static {}
pub trait Resource: Component<Mutability = Mutable> {}

/// A marker component for entities which store resources.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// A marker component for entities which store resources.
/// A marker component for entities that have a Resource component.

#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
reflect(Component, Default, Debug)
)]
#[derive(Component, Debug, Default)]
#[require(Internal)]
pub struct IsResource;

#[cfg(test)]
mod tests {
use crate::change_detection::MaybeLocation;
use crate::ptr::OwningPtr;
use crate::resource::Resource;
use crate::world::World;
use bevy_platform::prelude::String;

#[test]
fn unique_resource_entities() {
#[derive(Default, Resource)]
struct TestResource1;

#[derive(Resource)]
#[expect(dead_code, reason = "field needed for testing")]
struct TestResource2(String);

#[derive(Resource)]
#[expect(dead_code, reason = "field needed for testing")]
struct TestResource3(u8);

let mut world = World::new();
let start = world.entities().len();
world.init_resource::<TestResource1>();
assert_eq!(world.entities().len(), start + 1);
world.insert_resource(TestResource2(String::from("Foo")));
assert_eq!(world.entities().len(), start + 2);
// like component registration, which just makes it known to the world that a component exists,
// registering a resource should not spawn an entity.
let id = world.register_resource::<TestResource3>();
assert_eq!(world.entities().len(), start + 2);
OwningPtr::make(20_u8, |ptr| {
// SAFETY: id was just initialized and corresponds to a resource.
unsafe {
world.insert_resource_by_id(id, ptr, MaybeLocation::caller());
}
});
assert_eq!(world.entities().len(), start + 3);
assert!(world.remove_resource_by_id(id).is_some());
assert_eq!(world.entities().len(), start + 2);
world.remove_resource::<TestResource1>();
assert_eq!(world.entities().len(), start + 1);
// make sure that trying to add a resource twice results, doesn't change the entity count
world.insert_resource(TestResource2(String::from("Bar")));
assert_eq!(world.entities().len(), start + 1);
}
}
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ mod tests {
#[derive(Message)]
struct E;

#[derive(Resource, Component)]
#[derive(Resource)]
struct RC;

fn empty_system() {}
Expand Down
2 changes: 0 additions & 2 deletions crates/bevy_ecs/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ pub struct Storages {
pub sparse_sets: SparseSets,
/// Backing storage for [`Table`] components.
pub tables: Tables,
/// Backing storage for resources.
pub resources: Resources<true>,
/// Backing storage for `!Send` resources.
pub non_send_resources: Resources<false>,
Copy link
Member

Choose a reason for hiding this comment

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

In this new world, I think NonSend deserves a "reframe", as these are no longer "resources" in the same way. Ex: "NonSend data", or in this case Resources<false> -> NonSends

Copy link
Contributor

Choose a reason for hiding this comment

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

The current plan around NonSend was to just delete them and make users use thread locals. This is because we want to refactor the winit loop and accounting for moving the non send storage out of the world was making things too complicated. All the in engine uses have already been replaced with thread locals already. So we could just remove them if we want to merge this soon. But it might be better to deprecate them for 0.18 first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not familiar with the specifics of thread locals, but on the discord I have seen people vocal about keeping it. From what I've heard it's something few users need, but for specific usecases - like scripting - it's the indispensable. I am renaming doing the rename as suggested, but removing NonSendData is out of scope for this PR.

}
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/storage/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl<const SEND: bool> ResourceData<SEND> {
/// # Panics
/// If `SEND` is false, this will panic if a value is present and is not accessed from the
/// original thread it was inserted in.
#[expect(
dead_code,
reason = "To be removed later as part of resource-as-component efforts"
)]
pub(crate) fn get_mut(&mut self, last_run: Tick, this_run: Tick) -> Option<MutUntyped<'_>> {
let (ptr, ticks, caller) = self.get_with_ticks()?;
Some(MutUntyped {
Expand Down Expand Up @@ -210,6 +214,10 @@ impl<const SEND: bool> ResourceData<SEND> {
/// # Safety
/// - `value` must be valid for the underlying type for the resource.
#[inline]
#[expect(
dead_code,
reason = "To be removed later as part of resource-as-component efforts"
)]
pub(crate) unsafe fn insert_with_ticks(
&mut self,
value: OwningPtr<'_>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ mod tests {
entity::Entities,
error::Result,
prelude::{Component, Query},
reflect::ReflectResource,
reflect::{ReflectComponent, ReflectResource},
system::{Local, RunSystemOnce},
};
use alloc::vec;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ mod tests {
}
}

#[derive(Component, Resource)]
#[derive(Resource)]
struct W<T>(T);

fn simple_command(world: &mut World) {
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,17 @@ mod tests {
No,
}

#[derive(Component, Resource, Debug, Eq, PartialEq, Default)]
#[derive(Resource, Debug, Eq, PartialEq, Default)]
struct A;
#[derive(Component, Resource)]
#[derive(Resource)]
struct B;
#[derive(Component, Resource)]
#[derive(Resource)]
struct C;
#[derive(Component, Resource)]
#[derive(Resource)]
struct D;
#[derive(Component, Resource)]
#[derive(Resource)]
struct E;
#[derive(Component, Resource)]
#[derive(Resource)]
struct F;

#[derive(Component, Debug)]
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,9 @@ mod tests {

#[test]
fn run_system_once() {
#[derive(Resource)]
struct T(usize);

impl Resource for T {}

fn system(In(n): In<usize>, mut commands: Commands) -> usize {
commands.insert_resource(T(n));
n + 1
Expand Down Expand Up @@ -522,8 +521,8 @@ mod tests {

#[test]
fn run_system_once_invalid_params() {
#[derive(Resource)]
struct T;
impl Resource for T {}
fn system(_: Res<T>) {}

let mut world = World::default();
Expand Down
Loading
Loading