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.
This commit is contained in:
robtfm 2024-03-10 02:14:33 +00:00 committed by François
parent cc153ec930
commit 5c6628fe3c
No known key found for this signature in database
2 changed files with 2 additions and 2 deletions

View file

@ -109,6 +109,6 @@ pub fn no_automatic_morph_batching(
query: Query<Entity, (With<MeshMorphWeights>, Without<NoAutomaticBatching>)>,
) {
for entity in &query {
commands.entity(entity).insert(NoAutomaticBatching);
commands.entity(entity).try_insert(NoAutomaticBatching);
}
}

View file

@ -146,6 +146,6 @@ pub fn no_automatic_skin_batching(
query: Query<Entity, (With<SkinnedMesh>, Without<NoAutomaticBatching>)>,
) {
for entity in &query {
commands.entity(entity).insert(NoAutomaticBatching);
commands.entity(entity).try_insert(NoAutomaticBatching);
}
}