-
Taken from transform.rs: #[derive(Debug, PartialEq, Clone, Copy, Reflect)]
#[reflect(Component, PartialEq)]
pub struct Transform { What do |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
These are for "trait reflection". It is a way to connect trait methods to the reflection system. Without knowing the underlying type of a Due to the nature of the implementation, you generally can't do this for arbitrary traits. It must be explicitly supported by each trait. You can do this using the bevy/crates/bevy_reflect/src/reflect.rs Line 40 in 97d8e4e Support for custom traits must be added manually. For example, bevy/crates/bevy_ecs/src/reflect.rs Line 174 in 97d8e4e This might feel a bit ad-hoc, but note that Rust doesn't provide this functionality out of the box. We need these "weird" workarounds to wire things up properly. Note that you should avoid this pattern unless it is entirely necessary. Most situations will not require this level of dynamic typing and more traditional Rust patterns should be used (both for simplicity and for more performance). But some scenarios (like serialization and editors) benefit from the extra flexibility of reflected traits. |
Beta Was this translation helpful? Give feedback.
These are for "trait reflection". It is a way to connect trait methods to the reflection system. Without knowing the underlying type of a
Reflect
reference, you can call any registered trait method. Here is an example that explains this in a bit more detail.Due to the nature of the implementation, you generally can't do this for arbitrary traits. It must be explicitly supported by each trait. You can do this using the
reflect_trait
proc_macro, or by implementing it manually. The reflect crate provides built in support for common traits, such asSerialize
,Deserialize
,PartialEq
, andHash
. These "built in" traits can be accessed directly on the Reflect type:bevy/crates/bevy_reflect/sr…