Bevy version
main branch cb98d31
Operating system & version
Fedora 33
What you did
I'm trying to spawn a component with vec of Handle<Clip> with at least one instance, but Handle::<T>::clone_value() returns a boxed DynamicStruct instead of a clone of the Handle<T>, which leads to an error rising from the list_apply function that can't handle a DynamicStruct;
That also affects simple things like this:
use bevy::prelude::*;
#[derive(Default, Debug, Clone, Reflect)]
struct Something {
val: usize,
}
#[derive(Default, Debug, Reflect)]
#[reflect(Component)]
struct ComponentA {
list: Vec<Something>,
}
fn setup(mut commands: Commands, mut scenes: ResMut<Assets<Scene>>) {
let mut world = World::new();
world.spawn().insert(ComponentA {
list: vec![Something { val: 0 }],
});
let scene_handle = scenes.add(Scene::new(world));
commands.spawn_scene(scene_handle);
}
fn main() {
App::build()
.register_type::<ComponentA>()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.run();
}
even though Something implements Clone the Reflect::clone_value returns a DynamicStruct instead;
What you expected to happen
The scene should spawn no problem
What actually happened
Panics
thread 'main' panicked at 'Attempted to push invalid value of type bevy_animation_tests::Something.', /home/lassade/Rust/bevy/crates/bevy_reflect/src/impls/std.rs:59:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Segmentation fault (core dumped)
Additional information
My ideas to solve this issue are:
- Add support for
DynamicStructs in list_apply ()
- Change the
Reflect implementation for Handle<T>
- Maybe change the
Reflect behavior to require a Clone impl by default and add an option to use dynamic bundle instead
I think 1 and 2 must be done, 3 doesn't solve the problem but I think it at least will make it more clearer and maybe faster;
Bevy version
main branch cb98d31
Operating system & version
Fedora 33
What you did
I'm trying to spawn a component with vec of
Handle<Clip>with at least one instance, butHandle::<T>::clone_value()returns a boxedDynamicStructinstead of a clone of theHandle<T>, which leads to an error rising from thelist_applyfunction that can't handle aDynamicStruct;That also affects simple things like this:
even though
SomethingimplementsClonetheReflect::clone_valuereturns aDynamicStructinstead;What you expected to happen
The scene should spawn no problem
What actually happened
Panics
Additional information
My ideas to solve this issue are:
DynamicStructsinlist_apply()Reflectimplementation forHandle<T>Reflectbehavior to require a Clone impl by default and add an option to use dynamic bundle insteadI think 1 and 2 must be done, 3 doesn't solve the problem but I think it at least will make it more clearer and maybe faster;