11use crate :: menu:: components:: MenuRoot ;
2+ use crate :: menu:: main_menu:: components:: { MainMenuBackground , MainMenuMusic } ;
23use bevy:: prelude:: * ;
34
4- /// Cleans up main menu entities by despawning the root node
5- pub fn cleanup_main_menu ( mut commands : Commands , menu_root_query : Query < Entity , With < MenuRoot > > ) {
5+ /// Cleans up main menu entities including root, background, and music
6+ pub fn cleanup_main_menu (
7+ mut commands : Commands ,
8+ menu_root_query : Query < Entity , With < MenuRoot > > ,
9+ background_query : Query < Entity , With < MainMenuBackground > > ,
10+ music_query : Query < Entity , With < MainMenuMusic > > ,
11+ ) {
612 // Despawn the root entity recursively
713 if let Ok ( root_entity) = menu_root_query. get_single ( ) {
814 info ! ( "Despawning main menu root entity: {:?}" , root_entity) ;
@@ -20,6 +26,18 @@ pub fn cleanup_main_menu(mut commands: Commands, menu_root_query: Query<Entity,
2026 info ! ( "No MenuRoot entity found to clean up." ) ;
2127 }
2228
29+ // Despawn background entities
30+ for entity in background_query. iter ( ) {
31+ info ! ( "Despawning main menu background entity: {:?}" , entity) ;
32+ commands. entity ( entity) . despawn_recursive ( ) ;
33+ }
34+
35+ // Despawn music entities
36+ for entity in music_query. iter ( ) {
37+ info ! ( "Despawning main menu music entity: {:?}" , entity) ;
38+ commands. entity ( entity) . despawn_recursive ( ) ;
39+ }
40+
2341 // Log the completion of cleanup
2442 info ! ( "Main menu cleanup complete" ) ;
2543}
0 commit comments