You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Objective
We don't have reflection for resources.
## Solution
Introduce reflection for resources.
Continues bevyengine#3580 (by @Davier), related to bevyengine#3576.
---
## Changelog
### Added
* Reflection on a resource type (by adding `ReflectResource`):
```rust
#[derive(Reflect)]
#[reflect(Resource)]
struct MyResourse;
```
### Changed
* Rename `ReflectComponent::add_component` into `ReflectComponent::insert_component` for consistency.
## Migration Guide
* Rename `ReflectComponent::add_component` into `ReflectComponent::insert_component`.
/// Gets the value of this [`Component`] type from the entity as a reflected reference.
37
58
pubfnreflect_component<'a>(
38
59
&self,
39
60
world:&'aWorld,
@@ -42,6 +63,7 @@ impl ReflectComponent {
42
63
(self.reflect_component)(world, entity)
43
64
}
44
65
66
+
/// Gets the value of this [`Component`] type from the entity as a mutable reflected reference.
45
67
pubfnreflect_component_mut<'a>(
46
68
&self,
47
69
world:&'amutWorld,
@@ -56,7 +78,7 @@ impl ReflectComponent {
56
78
/// violating Rust's aliasing rules. To avoid this:
57
79
/// * Only call this method in an exclusive system to avoid sharing across threads (or use a
58
80
/// scheduler that enforces safe memory access).
59
-
/// * Don't call this method more than once in the same scope for a given component.
81
+
/// * Don't call this method more than once in the same scope for a given [`Component`].
60
82
pubunsafefnreflect_component_unchecked_mut<'a>(
61
83
&self,
62
84
world:&'aWorld,
@@ -65,6 +87,11 @@ impl ReflectComponent {
65
87
(self.reflect_component_mut)(world, entity)
66
88
}
67
89
90
+
/// Gets the value of this [`Component`] type from entity from `source_world` and [applies](Self::apply_component()) it to the value of this [`Component`] type in entity in `destination_world`.
91
+
///
92
+
/// # Panics
93
+
///
94
+
/// Panics if there is no [`Component`] of the given type or either entity does not exist.
/// This method does not prevent you from having two mutable pointers to the same data,
200
+
/// violating Rust's aliasing rules. To avoid this:
201
+
/// * Only call this method in an exclusive system to avoid sharing across threads (or use a
202
+
/// scheduler that enforces safe memory access).
203
+
/// * Don't call this method more than once in the same scope for a given [`Resource`].
204
+
pubunsafefnreflect_resource_unckecked_mut<'a>(
205
+
&self,
206
+
world:&'aWorld,
207
+
) -> Option<ReflectMut<'a>>{
208
+
(self.reflect_resource_unchecked_mut)(world)
209
+
}
210
+
211
+
/// Gets the value of this [`Resource`] type from `source_world` and [applies](Self::apply_resource()) it to the value of this [`Resource`] type in `destination_world`.
212
+
///
213
+
/// # Panics
214
+
///
215
+
/// Panics if there is no [`Resource`] of the given type.
0 commit comments