Add NavigationMesh debug when navmesh is added later through scripts

Add NavigationMesh debug when navmesh is added later through scripts

(cherry picked from commit b6eff47bac)
This commit is contained in:
smix8 2022-06-02 10:55:19 +02:00 committed by Rémi Verschelde
parent 5e31c3dbb5
commit 106bf9b793

View file

@ -139,6 +139,17 @@ void NavigationMeshInstance::set_navigation_mesh(const Ref<NavigationMesh> &p_na
NavigationServer::get_singleton()->region_set_navmesh(region, p_navmesh); NavigationServer::get_singleton()->region_set_navmesh(region, p_navmesh);
if (debug_view == nullptr && is_inside_tree() && navmesh.is_valid() && get_tree()->is_debugging_navigation_hint()) {
MeshInstance *dm = memnew(MeshInstance);
dm->set_mesh(navmesh->get_debug_mesh());
if (is_enabled()) {
dm->set_material_override(get_tree()->get_debug_navigation_material());
} else {
dm->set_material_override(get_tree()->get_debug_navigation_disabled_material());
}
add_child(dm);
debug_view = dm;
}
if (debug_view && navmesh.is_valid()) { if (debug_view && navmesh.is_valid()) {
Object::cast_to<MeshInstance>(debug_view)->set_mesh(navmesh->get_debug_mesh()); Object::cast_to<MeshInstance>(debug_view)->set_mesh(navmesh->get_debug_mesh());
} }