bevyengine/bevy · info · DirectionalNavigationError

No neighbor from {current_focus} in the {direction:?} direct

Error message

No neighbor from {current_focus} in the {direction:?} direction.

What it means

DirectionalNavigation::navigate found a current focus but the DirectionalNavigationMap has no neighbor for that entity in the requested direction. In the manual map, an unset direction resolves to NavNeighbor::Auto, which the plain DirectionalNavigation system parameter reports as this error (bevy_ui's AutoDirectionalNavigator instead resolves it geometrically).

Source

Thrown at crates/bevy_input_focus/src/directional_navigation.rs:443

                NavNeighbor::Set(new_focus) => {
                    self.focus.set(new_focus, FocusCause::Navigated);
                    Ok(new_focus)
                }
            }
        } else {
            Err(DirectionalNavigationError::NoFocus)
        }
    }
}

/// An error that can occur when navigating between focusable entities using [directional navigation](crate::directional_navigation).
#[derive(Debug, PartialEq, Clone, Error)]
pub enum DirectionalNavigationError {
    /// No focusable entity is currently set.
    #[error("No focusable entity is currently set.")]
    NoFocus,
    /// No neighbor in the requested direction.
    #[error("No neighbor from {current_focus} in the {direction:?} direction.")]
    NoNeighborInDirection {
        /// The entity that was the focus when the error occurred.
        current_focus: Entity,
        /// The direction in which the navigation was attempted.
        direction: CompassOctant,
    },
    /// Navigation explicitly blocked in the requested direction.
    #[error("Navigation explicitly blocked from {current_focus} in the {direction:?} direction.")]
    BlockedNavigation {
        /// The entity that was the focus when the error occurred.
        current_focus: Entity,
        /// The direction in which the navigation was attempted.
        direction: CompassOctant,
    },
}

/// A focusable area with position and size information.
///

View on GitHub (pinned to 396ca72708)

Solutions

  1. If using manual navigation, define edges for that direction with add_edge, add_edges, or add_looping_edges (looping edges give wrap-around menus).
  2. Treat the error as an expected boundary hit: log at debug level or ignore, since focus simply stays put.
  3. Verify the element you expect to reach actually has the Focusable component and is visible.

Example fix

// before: no edge defined for East -> NoNeighborInDirection at the right edge

// after: wrap-around menu edges
nav_map.add_looping_edges(&[item_a, item_b, item_c], CompassOctant::East);
Defensive patterns

Strategy: fallback

Validate before calling

use bevy_input_focus::directional_navigation::DirectionalNavigationMap;

fn has_neighbor_in(map: &DirectionalNavigationMap, focus: Entity, dir: CompassOctant) -> bool {
    map.get_neighbors(focus)
        .map(|n| n.get(dir).is_set())
        .unwrap_or(false)
}

Try / catch

match nav.navigate(dir) {
    Ok(next) => { /* focus already moved */ }
    Err(DirectionalNavigationError::NoNeighborInDirection { .. }) => {
        // boundary hit: keep focus, optionally wrap manually
    }
    Err(e) => warn!("{e}"),
}

Prevention

When it happens

Trigger: Calling navigate with a CompassOctant for which no manual edge was defined via DirectionalNavigationMap::add_edge / add_symmetrical_edge / add_edges, or (with automatic navigation) pressing a direction at the layout edge where no candidate focusable exists.

Common situations: Pressing right on the rightmost menu item; a UI with a single focusable element; the intended target lacks the Focusable component or is invisible; manual-navigation setups where only some directions were wired.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/6d8879a4efcc8efc. Report an issue: GitHub.