From cca4ab3663cb451318ac2eb48731eb9d476531c5 Mon Sep 17 00:00:00 2001 From: robtfm <50659922+robtfm@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:14:33 +0000 Subject: [PATCH] try_insert NoAutomaticBatching (#12396) # Objective fix occasional crash from commands.insert when quickly spawning and despawning skinned/morphed meshes ## Solution use `try_insert` instead of `insert`. if the entity is deleted we don't mind failing to add the `NoAutomaticBatching` marker. --- crates/bevy_pbr/src/render/morph.rs | 2 +- crates/bevy_pbr/src/render/skin.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/render/morph.rs b/crates/bevy_pbr/src/render/morph.rs index 7516bb495b7f1..cdc9c599ea24b 100644 --- a/crates/bevy_pbr/src/render/morph.rs +++ b/crates/bevy_pbr/src/render/morph.rs @@ -109,6 +109,6 @@ pub fn no_automatic_morph_batching( query: Query, Without)>, ) { for entity in &query { - commands.entity(entity).insert(NoAutomaticBatching); + commands.entity(entity).try_insert(NoAutomaticBatching); } } diff --git a/crates/bevy_pbr/src/render/skin.rs b/crates/bevy_pbr/src/render/skin.rs index 8ad3c35d6ee47..6a725b546c5e3 100644 --- a/crates/bevy_pbr/src/render/skin.rs +++ b/crates/bevy_pbr/src/render/skin.rs @@ -146,6 +146,6 @@ pub fn no_automatic_skin_batching( query: Query, Without)>, ) { for entity in &query { - commands.entity(entity).insert(NoAutomaticBatching); + commands.entity(entity).try_insert(NoAutomaticBatching); } }