Skip to content

Commit cfba731

Browse files
committed
Reflect Default for ComputedVisibility and Handle<T> (#6187)
# Objective - Reflecting `Default` is required for scripts to create `Reflect` types at runtime with no static type information. - Reflecting `Default` on `Handle<T>` 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<T>` 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<T>` and `ComputedVisibility`
1 parent f00212f commit cfba731

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

crates/bevy_asset/src/handle.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use crate::{
1010
Asset, Assets,
1111
};
1212
use bevy_ecs::{component::Component, reflect::ReflectComponent};
13-
use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize, ReflectSerialize};
13+
use bevy_reflect::{
14+
std_traits::ReflectDefault, FromReflect, Reflect, ReflectDeserialize, ReflectSerialize,
15+
};
1416
use bevy_utils::Uuid;
1517
use crossbeam_channel::{Receiver, Sender};
1618
use serde::{Deserialize, Serialize};
@@ -100,7 +102,7 @@ impl HandleId {
100102
/// collisions no longer being detected for that entity.
101103
///
102104
#[derive(Component, Reflect, FromReflect)]
103-
#[reflect(Component)]
105+
#[reflect(Component, Default)]
104106
pub struct Handle<T>
105107
where
106108
T: Asset,

crates/bevy_render/src/view/visibility/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Visibility {
5151

5252
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
5353
#[derive(Component, Clone, Reflect, Debug, Eq, PartialEq)]
54-
#[reflect(Component)]
54+
#[reflect(Component, Default)]
5555
pub struct ComputedVisibility {
5656
is_visible_in_hierarchy: bool,
5757
is_visible_in_view: bool,

0 commit comments

Comments
 (0)