Skip to content
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

examples: Add Dynamic Types reflection example #13220

Merged

Conversation

MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented May 3, 2024

Objective

Dynamic types can be tricky to understand and work with in bevy_reflect. There should be an example that shows what they are and how they're used.

Solution

Add a Dynamic Types reflection example.

I'm planning to go through the reflection examples, adding new ones and updating old ones. And I think this walkthrough style tends to work best. Due to the amount of text and associated explanation, it might fit better in a dedicated reflection chapter of the WIP Bevy Book. However, I think it might be valuable to have some public-facing tutorials for these concepts.

Let me know if there any thoughts or critiques with the example— both in content and this overall structure!

Testing

To test these changes, you can run the example locally:

cargo run --example dynamic_types

Changelog

  • Add Dynamic Types reflection example

@MrGVSV MrGVSV added C-Examples An addition or correction to our examples A-Reflection Runtime information about types labels May 3, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Really lovely! I was butting my head against this for the dev tools RFC and I'm grateful to have such a clear explanation to refer back to.

I'm perfectly fine with this style of material living in the examples for now. Like you said, I think it's a better fit for the book in the long-term, but we can cross that bridge later :)

Copy link
Contributor

@pablo-lua pablo-lua left a comment

Choose a reason for hiding this comment

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

Very good explanation on this feature! There is a very good amount of knowledge here that can be of use to beginners, all good.

@pablo-lua pablo-lua added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 3, 2024

// It also enables us to create a representation of a type without having compile-time
// access to the actual type. This is how the reflection deserializers work.
// They generally can't know how to construct a type ahead of time,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just so I understand; they could if we just provided an API typed_deserialize<T> -> T
(instead of the deserialize -> dyn Reflect that we have?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! I had considered mentioning how we could automatically use ReflectDefault or ReflectFromReflect internally but I figured that was an unnecessary technical note

Copy link
Contributor

@cBournhonesque cBournhonesque left a comment

Choose a reason for hiding this comment

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

Really useful explanation, love this!

@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 3, 2024
Merged via the queue into bevyengine:main with commit 4083750 May 3, 2024
35 checks passed
@MrGVSV MrGVSV deleted the mrgvsv/examples/dynamic-types branch May 3, 2024 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants