bevy_ecs::reflect

Function from_reflect_with_fallback

Source
pub fn from_reflect_with_fallback<T: Reflect + TypePath>(
    reflected: &dyn PartialReflect,
    world: &mut World,
    registry: &TypeRegistry,
) -> T
Available on crate feature bevy_reflect only.
Expand description

Creates a T from a &dyn PartialReflect.

This will try the following strategies, in this order:

  • use the reflected FromReflect, if it’s present and doesn’t fail;
  • use the reflected Default, if it’s present, and then call apply on the result;
  • use the reflected FromWorld, just like the Default.

The first one that is present and doesn’t fail will be used.

§Panics

If any strategy produces a Box<dyn Reflect> that doesn’t store a value of type T this method will panic.

If none of the strategies succeed, this method will panic.