Table of Contents

Class NavigationRegion2D

Namespace
Godot
Assembly
GodotSharp.dll

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 MapSetEdgeConnectionMargin(Rid, float).

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

public class NavigationRegion2D : Node2D, IDisposable
Inheritance
NavigationRegion2D
Implements
Inherited Members

Constructors

NavigationRegion2D()

public NavigationRegion2D()

Properties

AvoidanceLayers

A bitfield determining all avoidance layers for the avoidance constrain.

public uint AvoidanceLayers { get; set; }

Property Value

uint

ConstrainAvoidance

If true constraints avoidance agent's with an avoidance mask bit that matches with a bit of the AvoidanceLayers to the navigation polygon. Due to each navigation polygon outline creating an obstacle and each polygon edge creating an avoidance line constrain keep the navigation polygon shape as simple as possible for performance.

Experimental: This is an experimental feature and should not be used in production as agent's can get stuck on the navigation polygon corners and edges especially at high frame rate.

public bool ConstrainAvoidance { get; set; }

Property Value

bool

Enabled

Determines if the NavigationRegion2D is enabled or disabled.

public bool Enabled { get; set; }

Property Value

bool

EnterCost

When pathfinding enters this region's navigation mesh from another regions navigation mesh the EnterCost value is added to the path distance for determining the shortest path.

public float EnterCost { get; set; }

Property Value

float

NavigationLayers

A bitfield determining all navigation layers the region belongs to. These navigation layers can be checked upon when requesting a path with MapGetPath(Rid, Vector2, Vector2, bool, uint).

public uint NavigationLayers { get; set; }

Property Value

uint

NavigationPolygon

The NavigationPolygon resource to use.

public NavigationPolygon NavigationPolygon { get; set; }

Property Value

NavigationPolygon

TravelCost

When pathfinding moves inside this region's navigation mesh the traveled distances are multiplied with TravelCost for determining the shortest path.

public float TravelCost { get; set; }

Property Value

float

UseEdgeConnections

If enabled the navigation region will use edge connections to connect with other navigation regions within proximity of the navigation map edge connection margin.

public bool UseEdgeConnections { get; set; }

Property Value

bool

Methods

BakeNavigationPolygon(bool)

Bakes the NavigationPolygon. If onThread is set to true (default), the baking is done on a separate thread.

public void BakeNavigationPolygon(bool onThread = true)

Parameters

onThread bool

GetAvoidanceLayerValue(int)

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

public bool GetAvoidanceLayerValue(int layerNumber)

Parameters

layerNumber int

Returns

bool

GetNavigationLayerValue(int)

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

public bool GetNavigationLayerValue(int layerNumber)

Parameters

layerNumber int

Returns

bool

GetNavigationMap()

Returns the current navigation map Rid used by this region.

public Rid GetNavigationMap()

Returns

Rid

GetRegionRid()

Returns the Rid of this region on the NavigationServer2D.

Deprecated. Use GetRid() instead.

[Obsolete("This method is deprecated.")]
public Rid GetRegionRid()

Returns

Rid

GetRid()

Returns the Rid of this region on the NavigationServer2D. Combined with MapGetClosestPointOwner(Rid, Vector2) can be used to identify the NavigationRegion2D closest to a point on the merged navigation map.

public Rid GetRid()

Returns

Rid

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

SetAvoidanceLayerValue(int, bool)

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

public void SetAvoidanceLayerValue(int layerNumber, bool value)

Parameters

layerNumber int
value bool

SetNavigationLayerValue(int, bool)

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

public void SetNavigationLayerValue(int layerNumber, bool value)

Parameters

layerNumber int
value bool

SetNavigationMap(Rid)

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.

public void SetNavigationMap(Rid navigationMap)

Parameters

navigationMap Rid

Events

BakeFinished

Emitted when a navigation polygon bake operation is completed.

public event Action BakeFinished

Event Type

Action

NavigationPolygonChanged

Emitted when the used navigation polygon is replaced or changes to the internals of the current navigation polygon are committed.

public event Action NavigationPolygonChanged

Event Type

Action