Table of Contents

Class NavigationPolygon

A 2D navigation mesh that describes a traversable surface for pathfinding.

Inheritance
NavigationPolygon

A navigation mesh can be created either by baking it with the help of the NavigationServer2D, or by adding vertices and convex polygon indices arrays manually.

To bake a navigation mesh at least one outline needs to be added that defines the outer bounds of the baked area.

var new_navigation_mesh = NavigationPolygon.new()
var bounding_outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.add_outline(bounding_outline)
NavigationServer2D.bake_from_source_geometry_data(new_navigation_mesh, NavigationMeshSourceGeometryData2D.new());
$NavigationRegion2D.navigation_polygon = new_navigation_mesh

Adding vertices and polygon indices manually.

var new_navigation_mesh = NavigationPolygon.new()
var new_vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.vertices = new_vertices
var new_polygon_indices = PackedInt32Array([0, 1, 2, 3])
new_navigation_mesh.add_polygon(new_polygon_indices)
$NavigationRegion2D.navigation_polygon = new_navigation_mesh

See Also

Properties

The distance to erode/shrink the walkable surface when baking the navigation mesh.

var agent_radius : float = 10.0

Property Value

float
  • void set_agent_radius(float value)
  • float get_agent_radius

If the baking Rect2 has an area the navigation mesh baking will be restricted to its enclosing area.

var baking_rect : Rect2 = Rect2(0, 0, 0, 0)

Property Value

Rect2
  • void set_baking_rect(Rect2 value)
  • Rect2 get_baking_rect

The position offset applied to the baking_rect Rect2.

var baking_rect_offset : Vector2 = Vector2(0, 0)

Property Value

Vector2
  • void set_baking_rect_offset(Vector2 value)
  • Vector2 get_baking_rect_offset

The size of the non-navigable border around the bake bounding area defined by the baking_rect Rect2.

In conjunction with the baking_rect the border size can be used to bake tile aligned navigation meshes without the tile edges being shrunk by agent_radius.

var border_size : float = 0.0

Property Value

float
  • void set_border_size(float value)
  • float get_border_size

The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.

var cell_size : float = 1.0

Property Value

float
  • void set_cell_size(float value)
  • float get_cell_size

The physics layers to scan for static colliders.

Only used when parsed_geometry_type is NavigationPolygon.PARSED_GEOMETRY_STATIC_COLLIDERS or NavigationPolygon.PARSED_GEOMETRY_BOTH.

var parsed_collision_mask : int = 4294967295

Property Value

int
  • void set_parsed_collision_mask(int value)
  • int get_parsed_collision_mask

Determines which type of nodes will be parsed as geometry. See ParsedGeometryType for possible values.

var parsed_geometry_type : int = 2

Property Value

int
  • void set_parsed_geometry_type(int value)
  • int get_parsed_geometry_type

Partitioning algorithm for creating the navigation mesh polys. See SamplePartitionType for possible values.

var sample_partition_type : int = 0

Property Value

int
  • void set_sample_partition_type(int value)
  • int get_sample_partition_type

The group name of nodes that should be parsed for baking source geometry.

Only used when source_geometry_mode is NavigationPolygon.SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN or NavigationPolygon.SOURCE_GEOMETRY_GROUPS_EXPLICIT.

var source_geometry_group_name : StringName = &"navigation_polygon_source_geometry_group"

Property Value

StringName

The source of the geometry used when baking. See SourceGeometryMode for possible values.

var source_geometry_mode : int = 0

Property Value

int
  • void set_source_geometry_mode(int value)
  • int get_source_geometry_mode

Methods

Appends a PackedVector2Array that contains the vertices of an outline to the internal array that contains all the outlines.

void add_outline(PackedVector2Array outline)

Parameters

outline PackedVector2Array

Adds a PackedVector2Array that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.

void add_outline_at_index(PackedVector2Array outline, int index)

Parameters

outline PackedVector2Array
index int

Adds a polygon using the indices of the vertices you get when calling get_vertices.

void add_polygon(PackedInt32Array polygon)

Parameters

polygon PackedInt32Array

Clears the internal arrays for vertices and polygon indices.

void clear

Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.

void clear_outlines

Clears the array of polygons, but it doesn't clear the array of outlines and vertices.

void clear_polygons

Returns the NavigationMesh resulting from this navigation polygon. This navigation mesh can be used to update the navigation mesh of a region with the NavigationServer3D.region_set_navigation_mesh API directly (as 2D uses the 3D server behind the scene).

NavigationMesh get_navigation_mesh

Qualifiers: const

Returns a PackedVector2Array containing the vertices of an outline that was created in the editor or by script.

PackedVector2Array get_outline(int idx)

Parameters

idx int

Qualifiers: const

Returns the number of outlines that were created in the editor or by script.

int get_outline_count

Qualifiers: const

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

bool get_parsed_collision_mask_value(int layer_number)

Parameters

layer_number int

Returns a PackedInt32Array containing the indices of the vertices of a created polygon.

PackedInt32Array get_polygon(int idx)

Parameters

idx int

Qualifiers: const

Returns the count of all polygons.

int get_polygon_count

Qualifiers: const

Returns a PackedVector2Array containing all the vertices being used to create the polygons.

PackedVector2Array get_vertices

Creates polygons from the outlines added in the editor or by script.

void make_polygons_from_outlines

Removes an outline created in the editor or by script. You have to call make_polygons_from_outlines for the polygons to update.

void remove_outline(int idx)

Parameters

idx int

Changes an outline created in the editor or by script. You have to call make_polygons_from_outlines for the polygons to update.

void set_outline(int idx, PackedVector2Array outline)

Parameters

idx int
outline PackedVector2Array

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

void set_parsed_collision_mask_value(int layer_number, bool value)

Parameters

layer_number int
value bool

Sets the vertices that can be then indexed to create polygons with the NavigationPolygon.add_polygon method.

void set_vertices(PackedVector2Array vertices)

Parameters

vertices PackedVector2Array