use bevy_reflect::{PartialReflect, ReflectFromReflect, TypeRegistration};12/// Attempts to clone a [`PartialReflect`] value using various methods.3///4/// This first attempts to clone via [`PartialReflect::reflect_clone`].5/// then falls back to [`ReflectFromReflect::from_reflect`],6/// and finally [`PartialReflect::to_dynamic`] if the first two methods fail.7///8/// This helps ensure that the original type and type data is retained,9/// and only returning a dynamic type if all other methods fail.10pub(super) fn clone_reflect_value(11value: &dyn PartialReflect,12type_registration: &TypeRegistration,13) -> Box<dyn PartialReflect> {14value15.reflect_clone()16.map(PartialReflect::into_partial_reflect)17.unwrap_or_else(|_| {18type_registration19.data::<ReflectFromReflect>()20.and_then(|fr| fr.from_reflect(value.as_partial_reflect()))21.map(PartialReflect::into_partial_reflect)22.unwrap_or_else(|| value.to_dynamic())23})24}252627