Table of Contents

Class NavigationPolygon

Namespace
Godot
Assembly
GodotSharp.dll

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 newNavigationMesh = new NavigationPolygon();
  var boundingOutline = new Vector2[] { 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>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;

Adding vertices and polygon indices manually.

var newNavigationMesh = new NavigationPolygon();
  var newVertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  newNavigationMesh.Vertices = newVertices;
  var newPolygonIndices = new int[] { 0, 1, 2, 3 };
  newNavigationMesh.AddPolygon(newPolygonIndices);
  GetNode<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;
public class NavigationPolygon : Resource, IDisposable
Inheritance
NavigationPolygon
Implements
Inherited Members

Constructors

NavigationPolygon()

public NavigationPolygon()

Properties

AgentRadius

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

public float AgentRadius { get; set; }

Property Value

float

CellSize

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

public float CellSize { get; set; }

Property Value

float

Outlines

public Array<Vector2[]> Outlines { get; set; }

Property Value

Array<Vector2[]>

ParsedCollisionMask

The physics layers to scan for static colliders.

Only used when ParsedGeometryType is StaticColliders or Both.

public uint ParsedCollisionMask { get; set; }

Property Value

uint

ParsedGeometryType

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

public NavigationPolygon.ParsedGeometryTypeEnum ParsedGeometryType { get; set; }

Property Value

NavigationPolygon.ParsedGeometryTypeEnum

Polygons

public Array<int[]> Polygons { get; set; }

Property Value

Array<int[]>

SourceGeometryGroupName

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

Only used when SourceGeometryMode is GroupsWithChildren or GroupsExplicit.

public StringName SourceGeometryGroupName { get; set; }

Property Value

StringName

SourceGeometryMode

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

public NavigationPolygon.SourceGeometryModeEnum SourceGeometryMode { get; set; }

Property Value

NavigationPolygon.SourceGeometryModeEnum

Vertices

public Vector2[] Vertices { get; set; }

Property Value

Vector2[]

Methods

AddOutline(Vector2[])

Appends a Vector2[] that contains the vertices of an outline to the internal array that contains all the outlines.

public void AddOutline(Vector2[] outline)

Parameters

outline Vector2[]

AddOutlineAtIndex(Vector2[], int)

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

public void AddOutlineAtIndex(Vector2[] outline, int index)

Parameters

outline Vector2[]
index int

AddPolygon(int[])

Adds a polygon using the indices of the vertices you get when calling Godot.NavigationPolygon.GetVertices.

public void AddPolygon(int[] polygon)

Parameters

polygon int[]

Clear()

Clears the internal arrays for vertices and polygon indices.

public void Clear()

ClearOutlines()

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

public void ClearOutlines()

ClearPolygons()

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

public void ClearPolygons()

GetNavigationMesh()

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

public NavigationMesh GetNavigationMesh()

Returns

NavigationMesh

GetOutline(int)

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

public Vector2[] GetOutline(int idx)

Parameters

idx int

Returns

Vector2[]

GetOutlineCount()

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

public int GetOutlineCount()

Returns

int

GetParsedCollisionMaskValue(int)

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

public bool GetParsedCollisionMaskValue(int layerNumber)

Parameters

layerNumber int

Returns

bool

GetPolygon(int)

Returns a int[] containing the indices of the vertices of a created polygon.

public int[] GetPolygon(int idx)

Parameters

idx int

Returns

int[]

GetPolygonCount()

Returns the count of all polygons.

public int GetPolygonCount()

Returns

int

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

MakePolygonsFromOutlines()

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

Deprecated. This function is deprecated, and might be removed in a future release. Use ParseSourceGeometryData(NavigationPolygon, NavigationMeshSourceGeometryData2D, Node, Callable) and BakeFromSourceGeometryData(NavigationPolygon, NavigationMeshSourceGeometryData2D, Callable) instead.

[Obsolete("This method is deprecated.")]
public void MakePolygonsFromOutlines()

RemoveOutline(int)

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

public void RemoveOutline(int idx)

Parameters

idx int

SetOutline(int, Vector2[])

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

public void SetOutline(int idx, Vector2[] outline)

Parameters

idx int
outline Vector2[]

SetParsedCollisionMaskValue(int, bool)

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

public void SetParsedCollisionMaskValue(int layerNumber, bool value)

Parameters

layerNumber int
value bool