Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

NavigationRegion2D

Inherits: Node2D < CanvasItem < Node < Object

A traversable 2D region that NavigationAgent2Ds can use for pathfinding.

Description

A traversable 2D region based on a NavigationPolygon that NavigationAgent2Ds can use for pathfinding.

Two regions can be connected to each other if they share a similar edge. You can set the minimum distance between two vertices required to connect two edges by using NavigationServer2D.map_set_edge_connection_margin.

Note: Overlapping two regions’ navigation polygons is not enough for connecting two regions. They must share a similar edge.

The pathfinding cost of entering a region from another region can be controlled with the enter_cost value.

Note: This value is not added to the path cost when the start position is already inside this region.

The pathfinding cost of traveling distances inside this region can be controlled with the travel_cost multiplier.

Note: This node caches changes to its properties, so if you make changes to the underlying region RID in NavigationServer2D, they will not be reflected in this node’s properties.

Tutorials

Properties

int

avoidance_layers

1

bool

constrain_avoidance

false

bool

enabled

true

float

enter_cost

0.0

int

navigation_layers

1

NavigationPolygon

navigation_polygon

float

travel_cost

1.0

bool

use_edge_connections

true

Methods

bool

get_avoidance_layer_value ( int layer_number ) const

bool

get_navigation_layer_value ( int layer_number ) const

RID

get_region_rid ( ) const

void

set_avoidance_layer_value ( int layer_number, bool value )

void

set_navigation_layer_value ( int layer_number, bool value )


Property Descriptions

int avoidance_layers = 1

  • void set_avoidance_layers ( int value )

  • int get_avoidance_layers ( )

A bitfield determining all avoidance layers for the avoidance constrain.


bool constrain_avoidance = false

  • void set_constrain_avoidance ( bool value )

  • bool get_constrain_avoidance ( )

If true constraints avoidance agent’s with an avoidance mask bit that matches with a bit of the avoidance_layers to the navigation polygon. Due to each navigation polygon outline creating an obstacle and each polygon edge creating an avoidance line constrain keep the navigation polygon shape as simple as possible for performance.

Experimental: This is an experimental feature and should not be used in production as agent’s can get stuck on the navigation polygon corners and edges especially at high frame rate.


bool enabled = true

  • void set_enabled ( bool value )

  • bool is_enabled ( )

Determines if the NavigationRegion2D is enabled or disabled.


float enter_cost = 0.0

  • void set_enter_cost ( float value )

  • float get_enter_cost ( )

When pathfinding enters this region’s navigation mesh from another regions navigation mesh the enter_cost value is added to the path distance for determining the shortest path.


int navigation_layers = 1

  • void set_navigation_layers ( int value )

  • int get_navigation_layers ( )

A bitfield determining all navigation layers the region belongs to. These navigation layers can be checked upon when requesting a path with NavigationServer2D.map_get_path.


NavigationPolygon navigation_polygon

The NavigationPolygon resource to use.


float travel_cost = 1.0

  • void set_travel_cost ( float value )

  • float get_travel_cost ( )

When pathfinding moves inside this region’s navigation mesh the traveled distances are multiplied with travel_cost for determining the shortest path.


bool use_edge_connections = true

  • void set_use_edge_connections ( bool value )

  • bool get_use_edge_connections ( )

If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.


Method Descriptions

bool get_avoidance_layer_value ( int layer_number ) const

Returns whether or not the specified layer of the avoidance_layers bitmask is enabled, given a layer_number between 1 and 32.


bool get_navigation_layer_value ( int layer_number ) const

Returns whether or not the specified layer of the navigation_layers bitmask is enabled, given a layer_number between 1 and 32.


RID get_region_rid ( ) const

Returns the RID of this region on the NavigationServer2D. Combined with NavigationServer2D.map_get_closest_point_owner can be used to identify the NavigationRegion2D closest to a point on the merged navigation map.


void set_avoidance_layer_value ( int layer_number, bool value )

Based on value, enables or disables the specified layer in the avoidance_layers bitmask, given a layer_number between 1 and 32.


void set_navigation_layer_value ( int layer_number, bool value )

Based on value, enables or disables the specified layer in the navigation_layers bitmask, given a layer_number between 1 and 32.