:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/4.1/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/NavigationPolygon.xml. .. _class_NavigationPolygon: NavigationPolygon ================= **Inherits:** :ref:`Resource` **<** :ref:`RefCounted` **<** :ref:`Object` A navigation polygon that defines traversable areas and obstacles. .. rst-class:: classref-introduction-group Description ----------- There are two ways to create polygons. Either by using the :ref:`add_outline` method, or using the :ref:`add_polygon` method. Using :ref:`add_outline`: .. tabs:: .. code-tab:: gdscript var polygon = NavigationPolygon.new() var outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)]) polygon.add_outline(outline) polygon.make_polygons_from_outlines() $NavigationRegion2D.navigation_polygon = polygon .. code-tab:: csharp var polygon = new NavigationPolygon(); var outline = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) }; polygon.AddOutline(outline); polygon.MakePolygonsFromOutlines(); GetNode("NavigationRegion2D").NavigationPolygon = polygon; Using :ref:`add_polygon` and indices of the vertices array. .. tabs:: .. code-tab:: gdscript var polygon = NavigationPolygon.new() var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)]) polygon.vertices = vertices var indices = PackedInt32Array([0, 1, 2, 3]) polygon.add_polygon(indices) $NavigationRegion2D.navigation_polygon = polygon .. code-tab:: csharp var polygon = new NavigationPolygon(); var vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) }; polygon.Vertices = vertices; var indices = new int[] { 0, 1, 2, 3 }; polygon.AddPolygon(indices); GetNode("NavigationRegion2D").NavigationPolygon = polygon; .. rst-class:: classref-introduction-group Tutorials --------- - `2D Navigation Demo `__ - :doc:`Using NavigationMeshes <../tutorials/navigation/navigation_using_navigationmeshes>` .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +---------------------------+--------------------------------------------------------------+---------+ | :ref:`float` | :ref:`cell_size` | ``1.0`` | +---------------------------+--------------------------------------------------------------+---------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_outline` **(** :ref:`PackedVector2Array` outline **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_outline_at_index` **(** :ref:`PackedVector2Array` outline, :ref:`int` index **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_polygon` **(** :ref:`PackedInt32Array` polygon **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear_outlines` **(** **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear_polygons` **(** **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`NavigationMesh` | :ref:`get_navigation_mesh` **(** **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedVector2Array` | :ref:`get_outline` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_outline_count` **(** **)** |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_polygon` **(** :ref:`int` idx **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_polygon_count` **(** **)** |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedVector2Array` | :ref:`get_vertices` **(** **)** |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`make_polygons_from_outlines` **(** **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_outline` **(** :ref:`int` idx **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_outline` **(** :ref:`int` idx, :ref:`PackedVector2Array` outline **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertices` **(** :ref:`PackedVector2Array` vertices **)** | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_NavigationPolygon_property_cell_size: .. rst-class:: classref-property :ref:`float` **cell_size** = ``1.0`` .. rst-class:: classref-property-setget - void **set_cell_size** **(** :ref:`float` value **)** - :ref:`float` **get_cell_size** **(** **)** The cell size used to rasterize the navigation mesh vertices. Must match with the cell size on the navigation map. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_NavigationPolygon_method_add_outline: .. rst-class:: classref-method void **add_outline** **(** :ref:`PackedVector2Array` outline **)** Appends a :ref:`PackedVector2Array` that contains the vertices of an outline to the internal array that contains all the outlines. You have to call :ref:`make_polygons_from_outlines` in order for this array to be converted to polygons that the engine will use. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_add_outline_at_index: .. rst-class:: classref-method void **add_outline_at_index** **(** :ref:`PackedVector2Array` outline, :ref:`int` index **)** Adds a :ref:`PackedVector2Array` that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position. You have to call :ref:`make_polygons_from_outlines` in order for this array to be converted to polygons that the engine will use. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_add_polygon: .. rst-class:: classref-method void **add_polygon** **(** :ref:`PackedInt32Array` polygon **)** Adds a polygon using the indices of the vertices you get when calling :ref:`get_vertices`. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_clear_outlines: .. rst-class:: classref-method void **clear_outlines** **(** **)** Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_clear_polygons: .. rst-class:: classref-method void **clear_polygons** **(** **)** Clears the array of polygons, but it doesn't clear the array of outlines and vertices. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_get_navigation_mesh: .. rst-class:: classref-method :ref:`NavigationMesh` **get_navigation_mesh** **(** **)** Returns the :ref:`NavigationMesh` resulting from this navigation polygon. This navigation mesh can be used to update the navigation mesh of a region with the :ref:`NavigationServer3D.region_set_navigation_mesh` API directly (as 2D uses the 3D server behind the scene). .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_get_outline: .. rst-class:: classref-method :ref:`PackedVector2Array` **get_outline** **(** :ref:`int` idx **)** |const| Returns a :ref:`PackedVector2Array` containing the vertices of an outline that was created in the editor or by script. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_get_outline_count: .. rst-class:: classref-method :ref:`int` **get_outline_count** **(** **)** |const| Returns the number of outlines that were created in the editor or by script. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_get_polygon: .. rst-class:: classref-method :ref:`PackedInt32Array` **get_polygon** **(** :ref:`int` idx **)** Returns a :ref:`PackedInt32Array` containing the indices of the vertices of a created polygon. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_get_polygon_count: .. rst-class:: classref-method :ref:`int` **get_polygon_count** **(** **)** |const| Returns the count of all polygons. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_get_vertices: .. rst-class:: classref-method :ref:`PackedVector2Array` **get_vertices** **(** **)** |const| Returns a :ref:`PackedVector2Array` containing all the vertices being used to create the polygons. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_make_polygons_from_outlines: .. rst-class:: classref-method void **make_polygons_from_outlines** **(** **)** Creates polygons from the outlines added in the editor or by script. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_remove_outline: .. rst-class:: classref-method void **remove_outline** **(** :ref:`int` idx **)** Removes an outline created in the editor or by script. You have to call :ref:`make_polygons_from_outlines` for the polygons to update. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_set_outline: .. rst-class:: classref-method void **set_outline** **(** :ref:`int` idx, :ref:`PackedVector2Array` outline **)** Changes an outline created in the editor or by script. You have to call :ref:`make_polygons_from_outlines` for the polygons to update. .. rst-class:: classref-item-separator ---- .. _class_NavigationPolygon_method_set_vertices: .. rst-class:: classref-method void **set_vertices** **(** :ref:`PackedVector2Array` vertices **)** Sets the vertices that can be then indexed to create polygons with the :ref:`add_polygon` method. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`