bevyengine/bevy · error

expected reference value

Error message

expected reference value

What it means

Panic raised by Return::unwrap_ref when the wrapped Return value is not the Return::Ref variant (i.e. it is Owned or Mut). The caller asserted a reference return that does not exist, so the invariant of unwrap_ref is violated; the owned or mutable value cannot be re-borrowed as a shared reference.

Source

Thrown at crates/bevy_reflect/src/func/return_type.rs:54

    /// # Panics
    ///
    /// Panics if the return value is not [`Self::Owned`].
    pub fn unwrap_owned(self) -> Box<dyn PartialReflect> {
        match self {
            Return::Owned(value) => value,
            _ => panic!("expected owned value"),
        }
    }

    /// Unwraps the return value as a reference to a value.
    ///
    /// # Panics
    ///
    /// Panics if the return value is not [`Self::Ref`].
    pub fn unwrap_ref(self) -> &'a dyn PartialReflect {
        match self {
            Return::Ref(value) => value,
            _ => panic!("expected reference value"),
        }
    }

    /// Unwraps the return value as a mutable reference to a value.
    ///
    /// # Panics
    ///
    /// Panics if the return value is not [`Self::Mut`].
    pub fn unwrap_mut(self) -> &'a mut dyn PartialReflect {
        match self {
            Return::Mut(value) => value,
            _ => panic!("expected mutable reference value"),
        }
    }
}

/// A trait for types that can be converted into a [`Return`] value.
///

View on GitHub (pinned to 396ca72708)

Solutions

  1. Check Return::is_ref() before unwrapping
  2. Use unwrap_owned or unwrap_mut as appropriate for the actual variant
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/bevy_reflect/src/func/return_type.rs:54 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/8ac62ed5a85a81bc. Report an issue: GitHub.