bevy_mod_picking icon indicating copy to clipboard operation
bevy_mod_picking copied to clipboard

Despawning child UI elements will let picking through parent UI element

Open pinkponk opened this issue 2 years ago • 0 comments

My problem was that when a user clicked a UI button I rebuilt some of the UI (Despawned the button and other stuff). I kept a root node which an interaction component which normally blocks picking but when button is being despawned the interaction for the root node is still set to Interaction::None and there will be a 1 frame picking until the root node trigger its interaction::Hovered.

I fix this in my code with manually setting the Interaction to Hovered for the underlying parent root node whenever I despawn ui elements and the cursor is already on said despawned ui elements.

if let Ok((entity, mut interaction)) = root_node_query.get_single_mut() {
  commands.entity(entity).despawn_descendants(); //Will cause the 1 frame picking pass-through
  *interaction = Interaction::Hovered; //Will stop the 1 frame picking pass-through
}

I don't know how this would be fixed with bevy_mod_picking. Maybe this is more of a bevy ui thing to fix?

pinkponk avatar Jul 25 '22 14:07 pinkponk