diff --git a/modules/tile_map/doc_classes/TileMap.xml b/modules/tile_map/doc_classes/TileMap.xml index 7566b2102..3e8b2523c 100644 --- a/modules/tile_map/doc_classes/TileMap.xml +++ b/modules/tile_map/doc_classes/TileMap.xml @@ -153,6 +153,19 @@ + + + + + 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. + + + + + + Returns the current navigation map [RID] use by this region. + + diff --git a/modules/tile_map/tile_map.cpp b/modules/tile_map/tile_map.cpp index f0bf46bcd..5cb1e419d 100644 --- a/modules/tile_map/tile_map.cpp +++ b/modules/tile_map/tile_map.cpp @@ -68,8 +68,6 @@ void TileMap::_notification(int p_what) { while (c) { navigation = Object::cast_to(c); if (navigation) { - // only for <3.5 backward compatibility - bake_navigation = true; break; } @@ -697,11 +695,7 @@ void TileMap::update_dirty_quadrants() { RID region = Navigation2DServer::get_singleton()->region_create(); Navigation2DServer::get_singleton()->region_set_owner_id(region, get_instance_id()); - if (navigation) { - Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); - } else { - Navigation2DServer::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); - } + Navigation2DServer::get_singleton()->region_set_map(region, get_navigation_map()); Navigation2DServer::get_singleton()->region_set_navigation_layers(region, navigation_layers); Navigation2DServer::get_singleton()->region_set_transform(region, nav_rel * xform); Navigation2DServer::get_singleton()->region_set_navigation_polygon(region, navigation_polygon); @@ -1771,6 +1765,29 @@ bool TileMap::is_centered_textures_enabled() const { return centered_textures; } +void TileMap::set_navigation_map(RID p_navigation_map) { + if (navigation_map_override == p_navigation_map) { + return; + } + + navigation_map_override = p_navigation_map; + + for (RBMap::Element *E = quadrant_map.front(); E; E = E->next()) { + _make_quadrant_dirty(E); + } +} + +RID TileMap::get_navigation_map() const { + if (navigation_map_override.is_valid()) { + return navigation_map_override; + } else if (navigation) { + return navigation->get_rid(); + } else if (is_inside_tree()) { + return get_world_2d()->get_navigation_map(); + } + return RID(); +} + Array TileMap::get_used_cells() const { Array a; a.resize(tile_map.size()); @@ -1961,6 +1978,9 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("fix_invalid_tiles"), &TileMap::fix_invalid_tiles); ClassDB::bind_method(D_METHOD("clear"), &TileMap::clear); + ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &TileMap::set_navigation_map); + ClassDB::bind_method(D_METHOD("get_navigation_map"), &TileMap::get_navigation_map); + ClassDB::bind_method(D_METHOD("get_used_cells"), &TileMap::get_used_cells); ClassDB::bind_method(D_METHOD("get_used_cells_by_id", "id"), &TileMap::get_used_cells_by_id); ClassDB::bind_method(D_METHOD("get_used_rect"), &TileMap::get_used_rect); diff --git a/modules/tile_map/tile_map.h b/modules/tile_map/tile_map.h index 2817bb6ee..a3a3e6319 100644 --- a/modules/tile_map/tile_map.h +++ b/modules/tile_map/tile_map.h @@ -79,6 +79,7 @@ private: bool use_parent; CollisionObject2D *collision_parent; bool use_kinematic; + RID navigation_map_override; Navigation2D *navigation; bool bake_navigation; uint32_t navigation_layers; @@ -350,6 +351,9 @@ public: void set_centered_textures(bool p_enable); bool is_centered_textures_enabled() const; + void set_navigation_map(RID p_navigation_map); + RID get_navigation_map() const; + // TODO change these to PoolVector2iArrays Array get_used_cells() const; Array get_used_cells_by_id(int p_id) const;