{"record":{"id":"bdcb7996f8b895a0","repo":"bevyengine/bevy","slug":"no-focusable-entity-is-currently-set","errorCode":null,"errorMessage":"No focusable entity is currently set.","messagePattern":"No focusable entity is currently set\\.","errorType":"exception","errorClass":"DirectionalNavigationError","httpStatus":null,"severity":"warning","filePath":"crates/bevy_input_focus/src/directional_navigation.rs","lineNumber":440,"sourceCode":"                    current_focus,\n                    direction,\n                }),\n                NavNeighbor::Set(new_focus) => {\n                    self.focus.set(new_focus, FocusCause::Navigated);\n                    Ok(new_focus)\n                }\n            }\n        } else {\n            Err(DirectionalNavigationError::NoFocus)\n        }\n    }\n}\n\n/// An error that can occur when navigating between focusable entities using [directional navigation](crate::directional_navigation).\n#[derive(Debug, PartialEq, Clone, Error)]\npub enum DirectionalNavigationError {\n    /// No focusable entity is currently set.\n    #[error(\"No focusable entity is currently set.\")]\n    NoFocus,\n    /// No neighbor in the requested direction.\n    #[error(\"No neighbor from {current_focus} in the {direction:?} direction.\")]\n    NoNeighborInDirection {\n        /// The entity that was the focus when the error occurred.\n        current_focus: Entity,\n        /// The direction in which the navigation was attempted.\n        direction: CompassOctant,\n    },\n    /// Navigation explicitly blocked in the requested direction.\n    #[error(\"Navigation explicitly blocked from {current_focus} in the {direction:?} direction.\")]\n    BlockedNavigation {\n        /// The entity that was the focus when the error occurred.\n        current_focus: Entity,\n        /// The direction in which the navigation was attempted.\n        direction: CompassOctant,\n    },\n}","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_input_focus/src/directional_navigation.rs#L422-L458","documentation":"Returned by DirectionalNavigation::navigate (crates/bevy_input_focus/src/directional_navigation.rs:410) when the InputFocus resource holds no focused entity. Directional navigation finds the neighbor of the currently focused entity in a CompassOctant direction; with no focus set there is no origin entity to search from, so the call fails before any map lookup happens.","triggerScenarios":"Calling DirectionalNavigation::navigate(direction) (or gamepad/arrow-key input driving it) while InputFocus::get() returns None. Common on the first frames of a UI that never set an initial focus, or right after the focused entity was despawned or focus was cleared.","commonSituations":"A menu scene that never assigns an initial focus; the focused button is despawned when a submenu closes; focus was cleared and the player presses a d-pad direction; game builds where only keyboard users hit it because mouse users always click first.","solutions":["Set an initial focus when the UI opens: TabNavigation::initialize(menu_root, NavAction::Next) then input_focus.set(entity, FocusCause::Navigated), or set InputFocus directly to a default Focusable entity.","Handle Err(DirectionalNavigationError::NoFocus) by picking the first focusable entity and focusing it instead of propagating the error.","When despawning the currently focused entity, clear or transfer InputFocus in the same frame."],"exampleFix":"// before\nlet next = nav.navigate(CompassOctant::East)?; // fails when nothing is focused\n\n// after\nmatch nav.navigate(CompassOctant::East) {\n    Ok(next) => debug!(\"focused {next}\"),\n    Err(DirectionalNavigationError::NoFocus) => {\n        if let Ok(first) = tab_nav.initialize(menu_root, NavAction::Next) {\n            input_focus.set(first, FocusCause::Navigated);\n        }\n    }\n    Err(e) => warn!(\"navigation failed: {e}\"),\n}","handlingStrategy":"validation","validationCode":"use bevy_input_focus::prelude::*;\n\nfn can_navigate(input_focus: &InputFocus) -> bool {\n    input_focus.get().is_some()\n}\n\n// in your system:\nif can_navigate(&input_focus) {\n    let _ = nav.navigate(direction);\n} else {\n    // set an initial focus first, e.g. via TabNavigation::initialize\n}","typeGuard":null,"tryCatchPattern":"match nav.navigate(direction) {\n    Ok(entity) => debug!(\"focused {entity}\"),\n    Err(DirectionalNavigationError::NoFocus) => { /* pick and set an initial Focusable */ }\n    Err(e) => warn!(\"navigation failed: {e}\"),\n}","preventionTips":["Set an initial focus whenever a navigable UI becomes visible.","Clear or transfer focus when despawning the focused entity.","Treat NoFocus as an expected recoverable case, never unwrap() navigate results."],"tags":["bevy","input-focus","directional-navigation","ui","gamepad","ecs"],"backgroundTag":"no-focused-element","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}