bevyengine/bevy · error
Cannot call `ReflectComponent::apply` on component {name}. I
Error message
Cannot call `ReflectComponent::apply` on component {name}. It is immutable, and cannot modified through reflection What it means
Panics inside the ReflectComponentFns::apply closure when code attempts to mutate a component through reflection while the component was registered as immutable (Component<Mutability = Immutable>). ReflectComponent has no fallible mutation API, so the mutation is rejected by panicking.
Source
Thrown at crates/bevy_ecs/src/reflect/component.rs:324
}
}
impl<C: Component + Reflect + TypePath> CreateTypeData<C> for ReflectComponent {
fn create_type_data(_input: ()) -> Self {
// TODO: Currently we panic if a component is immutable and you use
// reflection to mutate it. Perhaps the mutation methods should be fallible?
ReflectComponent(ReflectComponentFns {
insert: |entity, reflected_component, registry| {
let component = entity.world_scope(|world| {
from_reflect_with_fallback::<C>(reflected_component, world, registry)
});
entity.insert(component);
},
apply: |mut entity, reflected_component| {
if !C::Mutability::MUTABLE {
let name = DebugName::type_name::<C>();
let name = name.shortname();
panic!("Cannot call `ReflectComponent::apply` on component {name}. It is immutable, and cannot modified through reflection");
}
// SAFETY: guard ensures `C` is a mutable component
let mut component = unsafe { entity.get_mut_assume_mutable::<C>() }.unwrap();
component.apply(reflected_component);
},
apply_or_insert_mapped: |entity,
reflected_component,
registry,
mut mapper,
relationship_hook_mode| {
if C::Mutability::MUTABLE {
// SAFETY: guard ensures `C` is a mutable component
if let Some(mut component) = unsafe { entity.get_mut_assume_mutable::<C>() } {
component.apply(reflected_component.as_partial_reflect());
C::map_entities(&mut component, &mut mapper);
} else {
let mut component = entity.world_scope(|world| {View on GitHub (pinned to 396ca72708)
Solutions
- Do not mutate immutable components via ReflectComponent::apply; treat them as read-only
- Declare the component as mutable (remove the Immutable mutability parameter) if reflective mutation is required
- Read the component value via reflection and write a new value through a dedicated command/system instead
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/src/reflect/component.rs:324 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/08a3ac808a5860c0.
Report an issue: GitHub.