godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.12k stars 20.2k forks source link

Navigation mesh debug does not appear for mesh generated in code #68400

Closed liabilityluke closed 1 year ago

liabilityluke commented 1 year ago

Godot version

4.0 alpha 4

System information

Windows 10

Issue description

When creating a navigation mesh in code using either add_polygon() or create_from_mesh(), the Navigation Debug tools do nothing.

Steps to reproduce

To use the MRP, ensure the debug option "Visible Navigation" is enabled. When the project is ran, the sphere will navigate toward the target, but no navigation mesh will be visible.

Minimal reproduction project

Manual Navmesh.zip

smix8 commented 1 year ago

The NavigationRegion3D only triggers updates for debug if a NEW NavigationMesh resource is set. This was necessary cause especially with procedual navmesh creation and tool scripts users were triggering so many updates at the same time that sometimes even the Editor would crash. You change data inside the resources but it is still the same resource so no debug updates. Try setting the navigation mesh resource to null before setting it again.

extends NavigationRegion3D

func _ready():
    var _navmesh : NavigationMesh = navmesh
    _navmesh.set_vertices([Vector3(-7, 0, -3.5), Vector3(7, 0, -3.5), Vector3(7, 0, 3.5), Vector3(-7, 0, 3.5)])
    _navmesh.add_polygon([0,1,2])
    _navmesh.add_polygon([0,2,3])
    navmesh = null
    navmesh = _navmesh