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
After some experimentation, I discovered that this mod does not support highlighting sprites; it just picks them.
Or I'm failing to configure the mod correctly, but after reviewing the code; none of the systems seem to trigger because they all rely on Handle<ColorMaterial> when Sprites use Handle<Image>. However, the sprites color overlay is controlled by the Sprite.color field.
Should we add support for highlighting sprites?
I'd be happy to submit a PR, but this POC might be considered naive, and there's probably a better way to incorporate this.
I tried my best to maintain the expectation that it would be using ColorMaterial so the existing API to use or override the GlobalHighlight or individual Highlight is still possible.
Below is my POC if interested:
POC
can be dropped into any project as a plugin that also uses the PickingPlugin with highlighting enabled
use bevy::prelude::*;#[cfg(feature = "egui")]use bevy_inspector_egui::prelude::*;use bevy_mod_picking::focus::PickingInteraction;use bevy_mod_picking::highlight::{GlobalHighlight,Highlight,InitialHighlight,PickHighlight};use bevy_mod_picking::picking_core::PickSet;use bevy_mod_picking::prelude::PickSelection;/// Automatically records the "initial" state of highlightable entities./// monkey patch for Spritefnget_sprite_initial_highlight_asset(mutcommands:Commands,mutcolors:ResMut<Assets<ColorMaterial>>,entity_asset_query:Query<(Entity,&Sprite),Added<PickHighlight>>,muthighlighting_query:Query<Option<&mutInitialHighlight<ColorMaterial>>>,){for(entity, sprite)in entity_asset_query.iter(){let color_handle = colors.add(ColorMaterial::from(sprite.color));
commands.entity(entity).insert(color_handle.clone());match highlighting_query.get_mut(entity){Ok(Some(mut highlighting)) => highlighting.initial = color_handle,
_ => {
commands.entity(entity).insert(InitialHighlight{initial: color_handle,});}}}}/// Apply highlighting assets to entities based on their state./// monkey patch for Spritefnupdate_sprite_highlight(global_defaults:Res<GlobalHighlight<ColorMaterial>>,color_materials:Res<Assets<ColorMaterial>>,mutquery:Query<(&mutSprite,&PickingInteraction,Option<&InitialHighlight<ColorMaterial>>,Option<&Highlight<ColorMaterial>>,),Changed<PickingInteraction>>,){for(mut sprite, picking_interaction, initial_highlight, highlight_override)in query.iter_mut(){let material_handle = match picking_interaction {PickingInteraction::Pressed => Some(global_defaults.pressed(&highlight_override)),PickingInteraction::Hovered => Some(global_defaults.hovered(&highlight_override)),PickingInteraction::None => initial_highlight.map_or(None, |h| Some(h.initial.to_owned())),};ifletSome(material_handle) = material_handle {ifletSome(color_material) = color_materials.get(material_handle){
sprite.color = color_material.color;}}}}/// If the interaction state of a selected entity is `None`, set the highlight color to `selected`./// monkey patch for Spritefnupdate_sprite_selection(global_defaults:Res<GlobalHighlight<ColorMaterial>>,color_materials:Res<Assets<ColorMaterial>>,mutinteraction_query:Query<(&mutSprite,&PickingInteraction,&PickSelection,&InitialHighlight<ColorMaterial>,Option<&Highlight<ColorMaterial>>,),Or<(Changed<PickSelection>,Changed<PickingInteraction>)>,>,){for(mut sprite, interaction, selection, init_highlight, h_override)in&mut interaction_query {ifletPickingInteraction::None = interaction {let material= if selection.is_selected{
global_defaults.selected(&h_override)}else{
init_highlight.initial.to_owned()};ifletSome(color_material) = color_materials.get(material){
sprite.color = color_material.color;}}}}pubstructSubPlugin;implPluginforSubPlugin{fnbuild(&self,app:&mutApp){
app
.add_systems(PreUpdate,(
get_sprite_initial_highlight_asset,
update_sprite_highlight,
update_sprite_selection,).chain().in_set(PickSet::Last));}}
The text was updated successfully, but these errors were encountered:
The highlighting plugin was built to support any asset type. You can add a HighlightingPlugin<Image>, which will allow you to swap out an entity's Image asset based on picking state. If we want to support changing properties other than assets, we should probably make a more generic highlighting plugin that can query any component on an entity. However, at this point, it sounds like it would be much simpler to implement this with an event listener.
After some experimentation, I discovered that this mod does not support highlighting sprites; it just picks them.
Or I'm failing to configure the mod correctly, but after reviewing the code; none of the systems seem to trigger because they all rely on
Handle<ColorMaterial>
when Sprites useHandle<Image>
. However, the sprites color overlay is controlled by theSprite.color
field.Should we add support for highlighting sprites?
I'd be happy to submit a PR, but this POC might be considered naive, and there's probably a better way to incorporate this.
I tried my best to maintain the expectation that it would be using
ColorMaterial
so the existing API to use or override theGlobalHighlight
or individualHighlight
is still possible.Below is my POC if interested:
POC
can be dropped into any project as a plugin that also uses the
PickingPlugin
with highlighting enabledThe text was updated successfully, but these errors were encountered: