Closed tavurth closed 1 year ago
Modifying the code thusly:
navreg.bake_navigation_mesh(false)
await get_tree().process_frame
Or by using the connect
callback
@tool
extends Node3D
func _ready() -> void:
var navreg = $NavigationRegion3D
navreg.bake_navigation_mesh(false)
navreg.connect("bake_finished", self._on_navigation_region_3d_bake_finished)
func _on_navigation_region_3d_bake_finished():
var navreg = $NavigationRegion3D
print(navreg.navmesh.get_vertices())
print(navreg.navmesh.get_polygon_count())
var to_save = preload("res://testresource.gd").new(navreg.navmesh)
ResourceSaver.save(
to_save,
"output.tres",
ResourceSaver.SaverFlags.FLAG_BUNDLE_RESOURCES
)
And I see the following output as expected:
[(0.5, 0.625, -1.25), (-0.25, 0.625, -1.5), (-0.5, 0.625, -1), (-0.5, 0.625, 0), (0.5, 0.625, 0.25)]
3
NavigationRegion3D.bake_navigation_mesh()
makes a deferred call to always finish on the main thread no matter what.
With the new thread-guards added in Godot 4 dev3 this is now more important than ever.
Godot version
v4.0.3.stable.official [5222a99f5]
System information
Mac
Issue description
The following code will not print any vertices, nor polygons. The
NavigationMesh
resource will not be saved correctly.Even though we specify
bake_navigation_mesh(false)
(on the main thread)Steps to reproduce
output.tres
Minimal reproduction project
test-navmesh.zip