impl Reflect and Debug for Mesh2dHandle (#4368)

# Objective

An entity spawned with `MaterialMesh2dBundle<M>` cannot be saved and spawned using `DynamicScene` because the `Mesh2dHandle` component does not `impl Reflect`.  

## Solution

Add `#[derive(Reflect)]` and `#[reflect(Component)]` to `Mesh2dHandle`, and call `register_type` in `SpritePlugin`.  Also add `#[derive(Debug)]` since I'm touching the `derive`s anyway.
This commit is contained in:
Chris Russell 2022-03-30 19:56:17 +00:00
parent 3537c6ae2d
commit 2b35dbabfd
2 changed files with 4 additions and 2 deletions

View file

@ -57,6 +57,7 @@ impl Plugin for SpritePlugin {
shaders.set_untracked(SPRITE_SHADER_HANDLE, sprite_shader);
app.add_asset::<TextureAtlas>()
.register_type::<Sprite>()
.register_type::<Mesh2dHandle>()
.add_plugin(Mesh2dRenderPlugin)
.add_plugin(ColorMaterialPlugin);

View file

@ -5,7 +5,7 @@ use bevy_ecs::{
system::{lifetimeless::*, SystemParamItem},
};
use bevy_math::{Mat4, Size};
use bevy_reflect::TypeUuid;
use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::{
mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout},
render_asset::RenderAssets,
@ -22,7 +22,8 @@ use bevy_transform::components::GlobalTransform;
/// Component for rendering with meshes in the 2d pipeline, usually with a [2d material](crate::Material2d) such as [`ColorMaterial`](crate::ColorMaterial).
///
/// It wraps a [`Handle<Mesh>`] to differentiate from the 3d pipelines which use the handles directly as components
#[derive(Default, Clone, Component)]
#[derive(Default, Clone, Component, Debug, Reflect)]
#[reflect(Component)]
pub struct Mesh2dHandle(pub Handle<Mesh>);
impl From<Handle<Mesh>> for Mesh2dHandle {