Inheritance #

RefCounted

- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
Resource

- Animation
- AnimationLibrary
- AnimationNode (6)
- AnimationNodeStateMachinePlayback
- AnimationNodeStateMachineTransition
- AudioBusLayout
- AudioEffect (17)
- AudioStream (10)
- BitMap
- BoneMap
- ButtonGroup
- CameraAttributes (2)
- ColorPalette
- Compositor
- CompositorEffect
- CryptoKey
- Curve
- Curve2D
- Curve3D
- EditorNode3DGizmoPlugin
- EditorSettings
- Environment
- Font (3)
- GDExtension
- GLTFAccessor
- GLTFAnimation
- GLTFBufferView
- GLTFCamera
- GLTFDocument (1)
- GLTFDocumentExtension (1)
- GLTFLight
- GLTFMesh
- GLTFNode
- GLTFPhysicsBody
- GLTFPhysicsShape
- GLTFSkeleton
- GLTFSkin
- GLTFSpecGloss
- GLTFState (1)
- GLTFTexture
- GLTFTextureSampler
- Gradient
- Image
- ImporterMesh
- InputEvent (6)
- JSON
- LabelSettings
- LightmapGIData
- Material (9)
- Mesh (4)
- MeshLibrary
- MissingResource
- MultiMesh
- NavigationMesh
- NavigationMeshSourceGeometryData2D
- NavigationMeshSourceGeometryData3D
- NavigationPolygon
- Noise (1)
- Occluder3D (5)
- OccluderPolygon2D
- OggPacketSequence
- OpenXRAction
- OpenXRActionMap
- OpenXRActionSet
- OpenXRBindingModifier (2)
- OpenXRHapticBase (1)
- OpenXRIPBinding
- OpenXRInteractionProfile
- PackedDataContainer
- PackedScene
- PhysicsMaterial
- PolygonPathFinder
- RDShaderFile
- RDShaderSPIRV
- RichTextEffect
- SceneReplicationConfig
- Script (3)
- Shader (1)
- ShaderInclude
- Shape2D (8)
- Shape3D (9)
- Shortcut
- SkeletonModification2D (7)
- SkeletonModificationStack2D
- SkeletonProfile (1)
- Skin
- Sky
- SpriteFrames
- StyleBox (4)
- SyntaxHighlighter (2)
- Texture (3)
- Theme
- TileMapPattern
- TileSet
- TileSetSource (2)
- Translation (1)
- VideoStream (1)
- VideoStreamPlayback
- VisualShaderNode (62)
- VoxelGIData
- World2D
- World3D
- X509Certificate
NavigationPolygon
Table of contents

NavigationPolygon #

is_refcounted, is_instantiable, resource, core, not_builtin_classes

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

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.

GDScript

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

C#

var newNavigationMesh = new NavigationPolygon();
Vector2[] boundingOutline = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
newNavigationMesh.AddOutline(boundingOutline);
NavigationServer2D.BakeFromSourceGeometryData(newNavigationMesh, new NavigationMeshSourceGeometryData2D());
GetNode("NavigationRegion2D").NavigationPolygon = newNavigationMesh;

Adding vertices and polygon indices manually.

GDScript

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

C#

var newNavigationMesh = new NavigationPolygon();
Vector2[] newVertices = [new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0)];
newNavigationMesh.Vertices = newVertices;
int[] newPolygonIndices = [0, 1, 2, 3];
newNavigationMesh.AddPolygon(newPolygonIndices);
GetNode("NavigationRegion2D").NavigationPolygon = newNavigationMesh;

Members #

var agent_radius: float = 10.0#

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

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 = PARSED_GEOMETRY_BOTH#

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

var sample_partition_type = SAMPLE_PARTITION_CONVEX_PARTITION#

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

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 = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN#

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

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(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 (as 2D uses the 3D server behind the scene).

const func get_outline(idx: int) -> PackedVector2Array#

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

const func get_outline_count() -> int#

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

const 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.

const func get_polygon_count() -> int#

Returns the count of all polygons.

const 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(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(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.

Annotations #

Constants #

const SAMPLE_PARTITION_CONVEX_PARTITION = 0 enum SamplePartitionType#

Convex partitioning that yields navigation mesh with convex polygons.

const SAMPLE_PARTITION_TRIANGULATE = 1 enum SamplePartitionType#

Triangulation partitioning that yields navigation mesh with triangle polygons.

const SAMPLE_PARTITION_MAX = 2 enum SamplePartitionType#

Represents the size of the SamplePartitionType enum.

const PARSED_GEOMETRY_MESH_INSTANCES = 0 enum ParsedGeometryType#

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.

const PARSED_GEOMETRY_STATIC_COLLIDERS = 1 enum ParsedGeometryType#

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

const PARSED_GEOMETRY_BOTH = 2 enum ParsedGeometryType#

Both PARSED_GEOMETRY_MESH_INSTANCES and PARSED_GEOMETRY_STATIC_COLLIDERS.

const PARSED_GEOMETRY_MAX = 3 enum ParsedGeometryType#

Represents the size of the ParsedGeometryType enum.

const SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0 enum SourceGeometryMode#

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

const SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1 enum SourceGeometryMode#

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

const SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2 enum SourceGeometryMode#

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

const SOURCE_GEOMETRY_MAX = 3 enum SourceGeometryMode#

Represents the size of the SourceGeometryMode enum.

Constructors #

Enums #

SamplePartitionType#

enum SamplePartitionType { SAMPLE_PARTITION_CONVEX_PARTITION = 0, SAMPLE_PARTITION_TRIANGULATE = 1, SAMPLE_PARTITION_MAX = 2, }

ParsedGeometryType#

enum ParsedGeometryType { PARSED_GEOMETRY_MESH_INSTANCES = 0, PARSED_GEOMETRY_STATIC_COLLIDERS = 1, PARSED_GEOMETRY_BOTH = 2, PARSED_GEOMETRY_MAX = 3, }

SourceGeometryMode#

enum SourceGeometryMode { SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0, SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN = 1, SOURCE_GEOMETRY_GROUPS_EXPLICIT = 2, SOURCE_GEOMETRY_MAX = 3, }

Operators #

Signals #

Theme Items #

Tutorials #