From 57b4f53d5dbaeda5e456d8aad718353c3df65b52 Mon Sep 17 00:00:00 2001 From: Zicklag Date: Thu, 6 Oct 2022 19:31:47 +0000 Subject: [PATCH] Reflect Default for `ComputedVisibility` and `Handle` (#6187) # Objective - Reflecting `Default` is required for scripts to create `Reflect` types at runtime with no static type information. - Reflecting `Default` on `Handle` and `ComputedVisibility` should allow scripts from `bevy_mod_js_scripting` to actually spawn sprites from scratch, without needing any hand-holding from the host-game. ## Solution - Derive `ReflectDefault` for `Handle` and `ComputedVisiblity`. --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section. - The `Default` trait is now reflected for `Handle` and `ComputedVisibility` --- crates/bevy_asset/src/handle.rs | 6 ++++-- crates/bevy_render/src/view/visibility/mod.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 4b1bab01a8ab3..c374c6b070ace 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -10,7 +10,9 @@ use crate::{ Asset, Assets, }; use bevy_ecs::{component::Component, reflect::ReflectComponent}; -use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize, ReflectSerialize}; +use bevy_reflect::{ + std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize, ReflectSerialize, +}; use bevy_utils::Uuid; use crossbeam_channel::{Receiver, Sender}; use serde::{Deserialize, Serialize}; @@ -100,7 +102,7 @@ impl HandleId { /// collisions no longer being detected for that entity. /// #[derive(Component, Reflect, FromReflect)] -#[reflect(Component)] +#[reflect(Component, Default)] pub struct Handle where T: Asset, diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index 099c1dbdcc56a..c703d64139d07 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -51,7 +51,7 @@ impl Visibility { /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering #[derive(Component, Clone, Reflect, Debug, Eq, PartialEq)] -#[reflect(Component)] +#[reflect(Component, Default)] pub struct ComputedVisibility { is_visible_in_hierarchy: bool, is_visible_in_view: bool,