bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Make `from_reflect_or_world` also try `ReflectDefault` and improve some comments and panic messages

Open SkiFire13 opened this issue 1 year ago • 0 comments

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.

SkiFire13 avatar Mar 15 '24 18:03 SkiFire13