NavigationRegion2D
A traversable 2D region that NavigationAgent2Ds can use for pathfinding.
A traversable 2D region that NavigationAgent2Ds can use for pathfinding.
A traversable 2D region based on a NavigationPolygon that NavigationAgent2Ds can use for pathfinding.
Two regions can be connected to each other if they share a similar edge. You can set the minimum distance between two vertices required to connect two edges by using NavigationServer2D.MapSetEdgeConnectionMargin.
Note: Overlapping two regions' navigation polygons is not enough for connecting two regions. They must share a similar edge.
The pathfinding cost of entering a region from another region can be controlled with the NavigationRegion2D.EnterCost value.
Note: This value is not added to the path cost when the start position is already inside this region.
The pathfinding cost of traveling distances inside this region can be controlled with the NavigationRegion2D.TravelCost multiplier.
Note: This node caches changes to its properties, so if you make changes to the underlying region Rid in NavigationServer2D, they will not be reflected in this node's properties.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
NavigationRegion2DConstructor
public NavigationRegion2D();Properties6
EnabledProperty
public bool Enabled { get; set; }Determines if the NavigationRegion2D is enabled or disabled.
EnterCostProperty
public float EnterCost { get; set; }When pathfinding enters this region's navigation mesh from another region's navigation mesh, this property's value is added to the path distance used to determine the shortest path.
NavigationLayersProperty
public uint NavigationLayers { get; set; }A bitfield determining all navigation layers the region belongs to. These navigation layers can be checked upon when requesting a path with NavigationServer2D.MapGetPath.
NavigationPolygonProperty
public NavigationPolygon NavigationPolygon { get; set; }The NavigationPolygon resource to use.
TravelCostProperty
public float TravelCost { get; set; }When pathfinding moves inside this region's navigation mesh the traveled distances are multiplied with NavigationRegion2D.TravelCost for determining the shortest path.
UseEdgeConnectionsProperty
public bool UseEdgeConnections { get; set; }If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.
Methods21
BakeNavigationPolygonvoid
public void BakeNavigationPolygon(bool onThread = true);Bakes the NavigationPolygon. If on_thread is set to true (default), the baking is done on a separate thread.
| Name | Type | Default |
|---|---|---|
onThread | bool | true |
GetBoundsRect2
public Rect2 GetBounds();Returns the axis-aligned rectangle for the region's transformed navigation mesh.
Rect2GetEnterCostfloat
public float GetEnterCost();floatGetNavigationLayerValuebool
public bool GetNavigationLayerValue(int layerNumber);Returns whether or not the specified layer of the NavigationRegion2D.NavigationLayers bitmask is enabled, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
boolGetNavigationLayersuint
public uint GetNavigationLayers();uintGetNavigationMapRid
public Rid GetNavigationMap();Returns the current navigation map Rid used by this region.
RidGetNavigationPolygonNavigationPolygon
public NavigationPolygon GetNavigationPolygon();NavigationPolygonGetRegionRidRid · Deprecated
public Rid GetRegionRid();Returns the Rid of this region on the NavigationServer2D.
RidGetRidRid
public Rid GetRid();Returns the Rid of this region on the NavigationServer2D. Combined with NavigationServer2D.MapGetClosestPointOwner can be used to identify the NavigationRegion2D closest to a point on the merged navigation map.
RidGetTravelCostfloat
public float GetTravelCost();floatGetUseEdgeConnectionsbool
public bool GetUseEdgeConnections();boolIsBakingbool
public bool IsBaking();Returns true when the NavigationPolygon is being baked on a background thread.
boolIsEnabledbool
public bool IsEnabled();boolSetEnabledvoid
public void SetEnabled(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetEnterCostvoid
public void SetEnterCost(float enterCost);| Name | Type | Default |
|---|---|---|
enterCost | float | — |
SetNavigationLayerValuevoid
public void SetNavigationLayerValue(int layerNumber, bool value);Based on value, enables or disables the specified layer in the NavigationRegion2D.NavigationLayers bitmask, given a layer_number between 1 and 32.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
SetNavigationLayersvoid
public void SetNavigationLayers(uint navigationLayers);| Name | Type | Default |
|---|---|---|
navigationLayers | uint | — |
SetNavigationMapvoid
public void SetNavigationMap(Rid navigationMap);Sets the Rid of the navigation map this region should use. By default the region will automatically join the World2D default navigation map so this function is only required to override the default map.
| Name | Type | Default |
|---|---|---|
navigationMap | Rid | — |
SetNavigationPolygonvoid
public void SetNavigationPolygon(NavigationPolygon navigationPolygon);| Name | Type | Default |
|---|---|---|
navigationPolygon | NavigationPolygon | — |
SetTravelCostvoid
public void SetTravelCost(float travelCost);| Name | Type | Default |
|---|---|---|
travelCost | float | — |
SetUseEdgeConnectionsvoid
public void SetUseEdgeConnections(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
Signals and events2
BakeFinishedEvent
public event Action BakeFinished;Emitted when a navigation polygon bake operation is completed.
NavigationPolygonChangedEvent
public event Action NavigationPolygonChanged;Emitted when the used navigation polygon is replaced or changes to the internals of the current navigation polygon are committed.