Skip to content

Commit

Permalink
Merge pull request #26 from mgi388/refs-25
Browse files Browse the repository at this point in the history
Tidy cache when StandardMaterial assets are removed
  • Loading branch information
merwaaan authored Dec 14, 2024
2 parents bf5861f + 1449f86 commit 478419a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Plugin for SpritesheetAnimationPlugin {
sprite3d::setup_rendering,
sprite3d::sync_when_sprites_change,
sprite3d::sync_when_atlases_change,
sprite3d::remove_dropped_standard_materials,
)
.in_set(Sprite3dSystemSet)
.after(AnimationSystemSet),
Expand Down
11 changes: 11 additions & 0 deletions src/systems/sprite3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,14 @@ fn get_or_create_mesh(
mesh_handle
})
}

pub(crate) fn remove_dropped_standard_materials(
mut cache: ResMut<Cache>,
mut standard_material_events: EventReader<AssetEvent<StandardMaterial>>,
) {
for event in standard_material_events.read() {
if let AssetEvent::Removed { id } = event {
cache.materials.retain(|_, handle| handle.id() != *id);
}
}
}

0 comments on commit 478419a

Please sign in to comment.