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

Make from_reflect_or_world also try ReflectDefault and improve some comments and panic messages #12499

Merged
merged 2 commits into from Apr 30, 2024

Conversation

SkiFire13
Copy link
Contributor

@SkiFire13 SkiFire13 commented Mar 15, 2024

Objective

  • from_reflect_or_world is an internal utilty used in the implementations of ReflectComponent and ReflectBundle to create a T given a &dyn Reflect by trying to use FromReflect, and if that fails it falls back to ReflectFromWorld
  • reflecting FromWorld is not intuitive though: often it is implicitly implemented by deriving Default so people might not even be aware of it.
  • the panic messages mentioning ReflectFromWorld are not directly correlated to what the user would have to do (reflect FromWorld)

Solution

  • Also check for ReflectDefault in addition to ReflectFromWorld.
  • Change the panic messages to mention the reflected trait rather than the Reflect* types.

Changelog

  • ReflectComponent and ReflectBundle no longer require T: FromReflect but instead only T: Reflect.
  • ReflectComponent and ReflectBundle will also work with types that only reflected Default and not FromWorld.

Migration Guide

  • ReflectBundle::insert now requires an additional &TypeRegistry parameter.

@MrGVSV MrGVSV added A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types labels Mar 15, 2024
crates/bevy_ecs/src/reflect/mod.rs Show resolved Hide resolved
crates/bevy_ecs/src/reflect/mod.rs Show resolved Hide resolved
crates/bevy_ecs/src/reflect/mod.rs Outdated Show resolved Hide resolved
@SkiFire13 SkiFire13 requested a review from MrGVSV March 16, 2024 12:34
@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 Apr 23, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 30, 2024
Merged via the queue into bevyengine:main with commit d9b6973 Apr 30, 2024
26 checks passed
@SkiFire13 SkiFire13 deleted the better-reflect-default-init branch April 30, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Reflection Runtime information about types C-Usability A simple quality-of-life change that makes Bevy easier to use 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