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
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
Enabled
Determines if the NavigationRegion2D is enabled or disabled.
public bool Enabled { get; set; }
Property Value
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
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
NavigationPolygon
The NavigationPolygon resource to use.
public NavigationPolygon NavigationPolygon { get; set; }
Property Value
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
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
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
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
GetNavigationMap()
Returns the current navigation map Rid used by this region.
public Rid GetNavigationMap()
Returns
GetRegionRid()
Returns the Rid of this region on the NavigationServer2D.
Deprecated. Use GetRid() instead.
[Obsolete("This method is deprecated.")]
public Rid GetRegionRid()
Returns
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
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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
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
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
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