-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
docs(example): Example how to insert reflected Component
onto entities
#17836
base: main
Are you sure you want to change the base?
Conversation
…into entities. # Objective We needed an example that showed how to insert a `Component` onto an entity that was deserialized into a type that implements `Reflect`. `ReflectCommandExt::insert_reflect` was not easy to discover. ## Solution This new example shows how to use `insert_reflect()`, while also showing how to deserialize data from glTF extras, and add the deserialized `Component`s automatically to the corresponding scene's children entities on instantiation.
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
IMO this example should be greatly reduced to essentially only the Something closer to this would make sense, without any gltf code. let json_component = r#"{"skein::tests::SomeThings":{"OneThing":{"name":"testing"}}}"#
let type_registry = type_registry.read();
let reflect_deserializer = ReflectDeserializer::new(&type_registry);
let mut deserializer = serde_json::Deserializer::from_str(value);
let reflect_value = reflect_deserializer
.deserialize(json_component)
.unwrap();
commands
.entity(entity)
.insert_reflect(reflect_value); Also ron is used in the other examples, I'm not sure if the Bevy repo has a preference for ron over serde_json for the examples |
The generated |
I'll remove the `load_gltf_components` in a later commit.
@ChristopherBiscardi, what do you think about this example. I've got both json and ron deserializing, and verify that the component is constructed properly. |
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.
overall lgtm.
A lot of the example is the same as examples/reflection/reflection.rs
but I think showing two different serializations (ron/json) is enough to validate the additional example even though insert_reflect
could be added to the other example.
I also dislike Foo/Bar naming but the other example this is extended from also uses Foo/Bar so matching that is probably better for ease of recognizing commonalities. CI is failing on the variable foo
though so that will have to change to merge.
Notably insert_reflect
is hard to find in the documentation because it is on an extension trait, so having an example for it is a good thing.
Objective
We needed an example that showed how to insert a
Component
onto an entity that was deserialized into a type that implementsReflect
.ReflectCommandExt::insert_reflect
was not easy to discover.Solution
This new example shows how to use
insert_reflect()
, while also showing how to deserialize data from glTF extras, and add the deserializedComponent
s automatically to the corresponding scene's children entities on instantiation.Testing
Tested locally on a Linux machine. Runs fine.
It's an example using standard features, so I assume it'll work where ever
Linux desktop machine. I could potentially test on other platforms like wasm, but I haven't yet.