-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Store Resources as components on singleton entities #20934
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
base: main
Are you sure you want to change the base?
Changes from 66 commits
042337f
47c20a5
64eac9a
956c1a6
073df4b
6c8281d
f9dc9f1
07723ac
1ba7af2
b89c042
9b33933
c7b4f1d
96aef45
e3ccd1b
5758134
9824c3a
9acf43f
da1d203
4d4e914
78a0672
4a2416d
3942c56
511e0b9
d4c98eb
724a4c4
f442ff6
acb539e
a0d76c3
c99df9c
12383a3
34570e8
f43905d
36e8191
d1b9b56
bfb2829
011b068
a12ec78
2261f8b
7f224be
4b0c77b
6fdf25e
2b1a5b5
e8c67cc
a01dc7d
9aecdf3
3ddf8bf
f0e973a
02c2b5f
8c1c818
1383efd
2f9990a
678da53
67810f4
af03cec
25b49d0
1117cfa
e3b12c2
33bd43d
18c7664
c75da2c
0e4d5c2
0eef31b
e68d5c2
44c526b
fb01522
d70a178
8afc908
44927a5
e953fa1
4cbdaa5
2ec2182
ea36fec
1203662
e751f15
2fa538e
740752d
737f04c
8a1727b
ff0e195
c9f7ec5
86962a8
3989f2e
d7d647e
6ceed0d
b2b2248
5028619
039cd0b
1014aad
9fd6129
485c03a
8c67aa3
fe921d2
75069d8
da3f903
2453314
c9c0f95
a4234fb
779b668
c919a69
5438039
4be1ccf
aa4d563
28ca0ac
411a681
a570cc3
e72f38e
a5e9612
73a9293
a3bef34
57ca7d6
3e36aba
31530f6
89c5622
f3153da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||||||
|
|
||||||
|
|
@@ -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. | ||||||
|
||||||
| /// A marker component for entities which store resources. | |
| /// A marker component for entities that have a Resource component. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>, | ||
|
||
| } | ||
|
|
||
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 would really prefer not to derive
Componentfor resources. Can't we just have astruct ResourceComponent<R: Resource>(R);instead?Also, I'm not sure why the order matterrs here, it seems irrelevant.
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.
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.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'm confused why the migration guide mentions them being marked as internal then.