You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, in Bevy, Require Components will override the components added within the on_add hook, so we can't use the require macro to add components that we want to initialize. This leads to two issues:
It becomes hard to easily see which components were added to the entity by the on_add hook.
We need to check within the hook whether the entity already has the components that need initialization, which increases boilerplate code.
Current Bevy
#[derive(Default,Component)]#[component(on_add = init_i18n_text)]pubstructI18nText{key:String,}fninit_i18n_text(){ifletSome(mut text) = world.get_mut::<Text>(entity){todo!();}else{
world
.commands().entity(entity).insert(Text::new(todo!();));}}
This suggestion
#[derive(Default,Component)]#[require(Text)]#[component(on_add = init_i18n_text)]pubstructI18nText{key:String,}fninit_i18n_text(){letmut text = world.get_mut::<Text>(entity).unwrap();todo!();}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently, in Bevy, Require Components will override the components added within the on_add hook, so we can't use the require macro to add components that we want to initialize. This leads to two issues:
Current Bevy
This suggestion
Beta Was this translation helpful? Give feedback.
All reactions