NavigationPolygon
A 2D navigation mesh that describes a traversable surface for pathfinding.
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.
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());
GetEntity<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;Adding vertices and polygon indices manually.
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);
GetEntity<NavigationRegion2D>("NavigationRegion2D").NavigationPolygon = newNavigationMesh;Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
NavigationPolygonConstructor
public NavigationPolygon();Properties13
AgentRadiusProperty
public float AgentRadius { get; set; }Clearance radius used when baking traversable geometry. Changing it does not automatically rebake existing output; inspect boundaries and paths after baking. It is not a physics-shape or avoidance radius.
BakingRectProperty
public Rect2 BakingRect { get; set; }If the baking Rect2 has an area the navigation mesh baking will be restricted to its enclosing area.
BakingRectOffsetProperty
public Vector2 BakingRectOffset { get; set; }The position offset applied to the NavigationPolygon.BakingRect Rect2.
BorderSizeProperty
public float BorderSize { get; set; }The size of the non-navigable border around the bake bounding area defined by the NavigationPolygon.BakingRect Rect2.
In conjunction with the NavigationPolygon.BakingRect the border size can be used to bake tile aligned navigation meshes without the tile edges being shrunk by NavigationPolygon.AgentRadius.
CellSizeProperty
public float CellSize { get; set; }The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map.
OutlinesProperty
public Reckfell.Collections.Array<Vector2[]> Outlines { get; set; }ParsedCollisionMaskProperty
public uint ParsedCollisionMask { get; set; }The physics layers to scan for static colliders.
Only used when NavigationPolygon.ParsedGeometryType is NavigationPolygon.ParsedGeometryTypeEnum.StaticColliders or NavigationPolygon.ParsedGeometryTypeEnum.Both.
ParsedGeometryTypeProperty
public NavigationPolygon.ParsedGeometryTypeEnum ParsedGeometryType { get; set; }Determines which type of nodes will be parsed as geometry.
PolygonsProperty
public Reckfell.Collections.Array<int[]> Polygons { get; set; }SamplePartitionTypeProperty
public NavigationPolygon.SamplePartitionTypeEnum SamplePartitionType { get; set; }Partitioning algorithm for creating the navigation mesh polys.
SourceGeometryGroupNameProperty
public StringName SourceGeometryGroupName { get; set; }The group name of nodes that should be parsed for baking source geometry.
Only used when NavigationPolygon.SourceGeometryMode is NavigationPolygon.SourceGeometryModeEnum.GroupsWithChildren or NavigationPolygon.SourceGeometryModeEnum.GroupsExplicit.
SourceGeometryModeProperty
public NavigationPolygon.SourceGeometryModeEnum SourceGeometryMode { get; set; }The source of the geometry used when baking.
VerticesProperty
public Vector2[] Vertices { get; set; }Methods43
AddOutline2 overloads
public void AddOutline(Vector2[] outline);Appends a Vector2[] that contains the vertices of an outline to the internal array that contains all the outlines.
| Name | Type | Default |
|---|---|---|
outline | Vector2[] | — |
public void AddOutline(ReadOnlySpan<Vector2> outline);Appends a Vector2[] that contains the vertices of an outline to the internal array that contains all the outlines.
| Name | Type | Default |
|---|---|---|
outline | ReadOnlySpan<Vector2> | — |
AddOutlineAtIndex2 overloads
public void AddOutlineAtIndex(Vector2[] outline, int index);Adds a Vector2[] that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.
| Name | Type | Default |
|---|---|---|
outline | Vector2[] | — |
index | int | — |
public void AddOutlineAtIndex(ReadOnlySpan<Vector2> outline, int index);Adds a Vector2[] that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position.
| Name | Type | Default |
|---|---|---|
outline | ReadOnlySpan<Vector2> | — |
index | int | — |
AddPolygon2 overloads
public void AddPolygon(int[] polygon);Adds a polygon using the indices of the vertices you get when calling NavigationPolygon.GetVertices.
| Name | Type | Default |
|---|---|---|
polygon | int[] | — |
public void AddPolygon(ReadOnlySpan<int> polygon);Adds a polygon using the indices of the vertices you get when calling NavigationPolygon.GetVertices.
| Name | Type | Default |
|---|---|---|
polygon | ReadOnlySpan<int> | — |
Clearvoid
public void Clear();Clears the internal arrays for vertices and polygon indices.
ClearOutlinesvoid
public void ClearOutlines();Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
ClearPolygonsvoid
public void ClearPolygons();Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
GetAgentRadiusfloat
public float GetAgentRadius();floatGetBakingRectRect2
public Rect2 GetBakingRect();Rect2GetBakingRectOffsetVector2
public Vector2 GetBakingRectOffset();Vector2GetBorderSizefloat
public float GetBorderSize();floatGetCellSizefloat
public float GetCellSize();floatGetNavigationMeshNavigationMesh
public NavigationMesh 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 NavigationServer3D.RegionSetNavigationMesh API directly.
NavigationMeshGetOutlineVector2[]
public Vector2[] GetOutline(int idx);Returns a Vector2[] containing the vertices of an outline that was created in the editor or by script.
| Name | Type | Default |
|---|---|---|
idx | int | — |
Vector2[]GetOutlineCountint
public int GetOutlineCount();Returns the number of outlines that were created in the editor or by script.
intGetParsedCollisionMaskuint
public uint GetParsedCollisionMask();uintGetParsedCollisionMaskValuebool
public bool GetParsedCollisionMaskValue(int layerNumber);Returns whether or not the specified layer of the NavigationPolygon.ParsedCollisionMask is enabled, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetParsedGeometryTypeNavigationPolygon.ParsedGeometryTypeEnum
public NavigationPolygon.ParsedGeometryTypeEnum GetParsedGeometryType();NavigationPolygon.ParsedGeometryTypeEnumGetPolygonint[]
public int[] GetPolygon(int idx);Returns a int[] containing the indices of the vertices of a created polygon.
| Name | Type | Default |
|---|---|---|
idx | int | — |
int[]GetPolygonCountint
public int GetPolygonCount();Returns the navigation resource polygon count. A positive count establishes data presence, rather than map readiness, target reachability or physical character clearance.
intPolygon count; zero means this resource has no prepared polygons.
GetSamplePartitionTypeNavigationPolygon.SamplePartitionTypeEnum
public NavigationPolygon.SamplePartitionTypeEnum GetSamplePartitionType();NavigationPolygon.SamplePartitionTypeEnumGetSourceGeometryGroupNameStringName
public StringName GetSourceGeometryGroupName();StringNameGetSourceGeometryModeNavigationPolygon.SourceGeometryModeEnum
public NavigationPolygon.SourceGeometryModeEnum GetSourceGeometryMode();NavigationPolygon.SourceGeometryModeEnumGetVerticesVector2[]
public Vector2[] GetVertices();Returns a Vector2[] containing all the vertices being used to create the polygons.
Vector2[]MakePolygonsFromOutlinesvoid · Deprecated
public void MakePolygonsFromOutlines();Creates polygons from the outlines added in the editor or by script.
RemoveOutlinevoid
public void RemoveOutline(int idx);Removes an outline created in the editor or by script. You have to call NavigationPolygon.MakePolygonsFromOutlines for the polygons to update.
| Name | Type | Default |
|---|---|---|
idx | int | — |
SetAgentRadiusvoid
public void SetAgentRadius(float agentRadius);| Name | Type | Default |
|---|---|---|
agentRadius | float | — |
SetBakingRectvoid
public void SetBakingRect(Rect2 rect);| Name | Type | Default |
|---|---|---|
rect | Rect2 | — |
SetBakingRectOffsetvoid
public void SetBakingRectOffset(Vector2 rectOffset);| Name | Type | Default |
|---|---|---|
rectOffset | Vector2 | — |
SetBorderSizevoid
public void SetBorderSize(float borderSize);| Name | Type | Default |
|---|---|---|
borderSize | float | — |
SetCellSizevoid
public void SetCellSize(float cellSize);| Name | Type | Default |
|---|---|---|
cellSize | float | — |
SetOutline2 overloads
public void SetOutline(int idx, Vector2[] outline);Changes an outline created in the editor or by script. You have to call NavigationPolygon.MakePolygonsFromOutlines for the polygons to update.
| Name | Type | Default |
|---|---|---|
idx | int | — |
outline | Vector2[] | — |
public void SetOutline(int idx, ReadOnlySpan<Vector2> outline);Changes an outline created in the editor or by script. You have to call NavigationPolygon.MakePolygonsFromOutlines for the polygons to update.
| Name | Type | Default |
|---|---|---|
idx | int | — |
outline | ReadOnlySpan<Vector2> | — |
SetParsedCollisionMaskvoid
public void SetParsedCollisionMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetParsedCollisionMaskValuevoid
public void SetParsedCollisionMaskValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the NavigationPolygon.ParsedCollisionMask, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetParsedGeometryTypevoid
public void SetParsedGeometryType(NavigationPolygon.ParsedGeometryTypeEnum geometryType);| Name | Type | Default |
|---|---|---|
geometryType | NavigationPolygon.ParsedGeometryTypeEnum | — |
SetSamplePartitionTypevoid
public void SetSamplePartitionType(NavigationPolygon.SamplePartitionTypeEnum samplePartitionType);| Name | Type | Default |
|---|---|---|
samplePartitionType | NavigationPolygon.SamplePartitionTypeEnum | — |
SetSourceGeometryGroupNamevoid
public void SetSourceGeometryGroupName(StringName groupName);| Name | Type | Default |
|---|---|---|
groupName | StringName | — |
SetSourceGeometryModevoid
public void SetSourceGeometryMode(NavigationPolygon.SourceGeometryModeEnum geometryMode);| Name | Type | Default |
|---|---|---|
geometryMode | NavigationPolygon.SourceGeometryModeEnum | — |
SetVertices2 overloads
public void SetVertices(Vector2[] vertices);Sets the vertices that can be then indexed to create polygons with the NavigationPolygon.AddPolygon method.
| Name | Type | Default |
|---|---|---|
vertices | Vector2[] | — |
public void SetVertices(ReadOnlySpan<Vector2> vertices);Sets the vertices that can be then indexed to create polygons with the NavigationPolygon.AddPolygon method.
| Name | Type | Default |
|---|---|---|
vertices | ReadOnlySpan<Vector2> | — |
NavigationPolygon.ParsedGeometryTypeEnum
| Value | Description |
|---|---|
Both = 2 | Both |
Max = 3 | Represents the size of the |
MeshInstances = 0 | Parses mesh instances as obstruction geometry. This includes |
StaticColliders = 1 | Parses |
NavigationPolygon.SamplePartitionTypeEnum
| Value | Description |
|---|---|
ConvexPartition = 0 | Convex partitioning that results in a navigation mesh with convex polygons. |
Max = 2 | Represents the size of the |
Triangulate = 1 | Triangulation partitioning that results in a navigation mesh with triangle polygons. |
NavigationPolygon.SourceGeometryModeEnum
| Value | Description |
|---|---|
GroupsExplicit = 2 | Uses nodes in a group for geometry. The group is specified by |
GroupsWithChildren = 1 | Scans nodes in a group and their child nodes recursively for geometry. The group is specified by |
Max = 3 | Represents the size of the |
RootNodeChildren = 0 | Scans the child nodes of the root node recursively for geometry. |