diff --git a/crates/bevy_ecs/src/system/commands.rs b/crates/bevy_ecs/src/system/commands.rs index 90adfb8dc510c..0ae01143043ef 100644 --- a/crates/bevy_ecs/src/system/commands.rs +++ b/crates/bevy_ecs/src/system/commands.rs @@ -4,7 +4,7 @@ use crate::{ entity::{Entities, Entity}, world::World, }; -use bevy_utils::tracing::debug; +use bevy_utils::tracing::{debug, warn}; use std::marker::PhantomData; /// A [`World`] mutation. @@ -353,7 +353,11 @@ where T: Component, { fn write(self: Box, world: &mut World) { - world.entity_mut(self.entity).insert(self.component); + if let Some(mut entity) = world.get_entity_mut(self.entity) { + entity.insert(self.component); + } else { + warn!("Attempt to write to entity that no longer exists"); + } } }