Index · Object → RefCounted → Resource → NavigationPolygon

NavigationPolygon

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

Class Description

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

Properties

var agent_radius: float = 10.0

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

Note: The radius must be equal or higher than 0.0. If the radius is 0.0, it won't be possible to fix invalid outline overlaps and other precision errors during the baking process. As a result, some obstacles may be excluded incorrectly from the final navigation mesh, or may delete the navigation mesh's polygons.

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

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

var baking_rect_offset: Vector2 = Vector2(0, 0)

The position offset applied to the baking_rect Rect2.

var border_size: float = 0.0

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 cell_size: float = 1.0

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

var parsed_collision_mask: int = 4294967295

The physics layers to scan for static colliders.

Only used when parsed_geometry_type is PARSED_GEOMETRY_STATIC_COLLIDERS or PARSED_GEOMETRY_BOTH.

var parsed_geometry_type: NavigationPolygon.ParsedGeometryType = 2

Determines which type of nodes will be parsed as geometry.

var sample_partition_type: NavigationPolygon.SamplePartitionType = 0

Partitioning algorithm for creating the navigation mesh polys.

var source_geometry_group_name: StringName = &"navigation_polygon_source_geometry_group"

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

Only used when source_geometry_mode is SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN or SOURCE_GEOMETRY_GROUPS_EXPLICIT.

var source_geometry_mode: NavigationPolygon.SourceGeometryMode = 0

The source of the geometry used when baking.

Inherited from Resource (4)

Methods

func add_outline(outline: PackedVector2Array) -> void

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

func add_outline_at_index(outline: PackedVector2Array, index: int) -> void

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

func add_polygon(polygon: PackedInt32Array) -> void

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

func clear() -> void

Clears the internal arrays for vertices and polygon indices.

func clear_outlines() -> void

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

func clear_polygons() -> void

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

func get_navigation_mesh() -> NavigationMesh

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.

func get_outline(idx: int) -> PackedVector2Array

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

func get_outline_count() -> int

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

func get_parsed_collision_mask_value(layer_number: int) -> bool

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

func get_polygon(idx: int) -> PackedInt32Array

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

func get_polygon_count() -> int

Returns the count of all polygons.

func get_vertices() -> PackedVector2Array

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

func make_polygons_from_outlines() -> void

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

func remove_outline(idx: int) -> void

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

func set_outline(idx: int, outline: PackedVector2Array) -> void

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

func set_parsed_collision_mask_value(layer_number: int, value: bool) -> void

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

func set_vertices(vertices: PackedVector2Array) -> void

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

Inherited from Resource (18)
func _get_rid() -> RID
func _reset_state() -> void
func _set_path_cache(path: String) -> void
func _setup_local_to_scene() -> void
func copy_from_resource(resource: Resource) -> Error
func duplicate(deep: bool = false) -> Resource
func duplicate_deep(deep_subresources_mode: Resource.DeepDuplicateMode = 1) -> Resource
func emit_changed() -> void
func get_rid() -> RID
func is_built_in() -> bool
func reset_state() -> void
func set_id_for_path(path: String, id: String) -> void
func set_path_cache(path: String) -> void
func setup_local_to_scene() -> void
func take_over_path(path: String) -> void
Inherited from RefCounted (4)
func init_ref() -> bool
func reference() -> bool
func unreference() -> bool
Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Resource (2)
signal changed()
Inherited from Object (2)

Enums & Constants

enum SamplePartitionType
SAMPLE_PARTITION_CONVEX_PARTITION = 0

Convex partitioning that results in a navigation mesh with convex polygons.

SAMPLE_PARTITION_TRIANGULATE = 1

Triangulation partitioning that results in a navigation mesh with triangle polygons.

SAMPLE_PARTITION_MAX = 2

Represents the size of the SamplePartitionType enum.

enum ParsedGeometryType
PARSED_GEOMETRY_MESH_INSTANCES = 0

Parses mesh instances as obstruction geometry. This includes Polygon2D, MeshInstance2D, MultiMeshInstance2D, and TileMap nodes.

Meshes are only parsed when they use a 2D vertices surface format.

PARSED_GEOMETRY_STATIC_COLLIDERS = 1

Parses StaticBody2D and TileMap colliders as obstruction geometry. The collider should be in any of the layers specified by parsed_collision_mask.

PARSED_GEOMETRY_BOTH = 2

Both PARSED_GEOMETRY_MESH_INSTANCES and PARSED_GEOMETRY_STATIC_COLLIDERS.

PARSED_GEOMETRY_MAX = 3

Represents the size of the ParsedGeometryType enum.

enum SourceGeometryMode
SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0

Scans the child nodes of the root node recursively for geometry.

SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1

Scans nodes in a group and their child nodes recursively for geometry. The group is specified by source_geometry_group_name.

SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2

Uses nodes in a group for geometry. The group is specified by source_geometry_group_name.

SOURCE_GEOMETRY_MAX = 3

Represents the size of the SourceGeometryMode enum.