{"record":{"id":"a28fe83bed7b9cc6","repo":"FyroxEngine/Fyrox","slug":"cast-to-failed-a28fe8","errorCode":null,"errorMessage":"Cast to {} failed!","messagePattern":"Cast to (.+?) failed!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/scene/node/mod.rs","lineNumber":476,"sourceCode":"    }\n}\n\n/// Defines as_(variant), as_mut_(variant) and is_(variant) methods.\n#[macro_export]\nmacro_rules! define_is_as {\n    ($typ:ty => fn $is:ident, fn $as_ref:ident, fn $as_mut:ident) => {\n        /// Returns true if node is instance of given type.\n        #[inline]\n        pub fn $is(&self) -> bool {\n            self.cast::<$typ>().is_some()\n        }\n\n        /// Tries to cast shared reference to a node to given type, panics if\n        /// cast is not possible.\n        #[inline]\n        pub fn $as_ref(&self) -> &$typ {\n            self.cast::<$typ>()\n                .unwrap_or_else(|| panic!(\"Cast to {} failed!\", stringify!($kind)))\n        }\n\n        /// Tries to cast mutable reference to a node to given type, panics if\n        /// cast is not possible.\n        #[inline]\n        pub fn $as_mut(&mut self) -> &mut $typ {\n            self.cast_mut::<$typ>()\n                .unwrap_or_else(|| panic!(\"Cast to {} failed!\", stringify!($kind)))\n        }\n    };\n}\n\nimpl Node {\n    /// Creates a new node instance from any type that implements [`NodeTrait`].\n    #[inline]\n    pub fn new<T: NodeTrait>(node: T) -> Self {\n        Self(Box::new(node))\n    }","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/scene/node/mod.rs#L458-L494","documentation":"This panic comes from a macro-generated node accessor (e.g. component_of/as_ref pattern) that calls Node::cast::<T>() and panics when the node cannot be downcast to the requested type. The message interpolates the type name via stringify!($kind).","triggerScenarios":"Calling a typed accessor such as node.as_light_ref() / component_of::<Mesh>() on a node whose underlying component is a different type (e.g. casting a Camera node to Light).","commonSituations":"Grabbing nodes by handle from a scene file whose node types changed; assuming a handle points to a specific kind after script/refactor changes; iterating pool nodes and applying type-specific calls unchecked.","solutions":["Use the non-panicking cast::<T>() which returns Option and handle the None case","Check node kind (is_light/is_mesh, etc.) or query components_of before casting","Fix the handle/source data so it actually contains the expected node type"],"exampleFix":"// before\nlet light = node.as_light_ref(); // panics if not a Light\n// after\nif let Some(light) = node.cast::<Light>() {\n    // use light\n}","handlingStrategy":"type-guard","validationCode":"if node.cast::<Light>().is_some() { /* safe to use typed accessors */ }","typeGuard":"fn as_light(node: &Node) -> Option<&Light> { node.cast::<Light>() }","tryCatchPattern":"let light = std::panic::catch_unwind(|| node.as_light_ref()).ok(); // prefer cast::<Light>()","preventionTips":["Prefer cast::<T>() (Option) over panicking typed accessors","Verify node type before calling as_*_ref/as_*_mut","Re-verify handles after scene data or format changes"],"tags":["casting","node","downcast","panic"],"backgroundTag":"type-mismatch","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}