diff --git a/doc/classes/TileMap.xml b/doc/classes/TileMap.xml
index 36312cac68d..48545128c88 100644
--- a/doc/classes/TileMap.xml
+++ b/doc/classes/TileMap.xml
@@ -326,6 +326,9 @@
The light mask assigned to all light occluders in the TileMap. The TileSet's light occluders will cast shadows only from Light2D(s) that have the same light mask(s).
+
+ If [code]true[/code], collision shapes are shown in the editor and at run-time. Requires [b]Visible Collision Shapes[/b] to be enabled in the [b]Debug[/b] menu for collision shapes to be visible at run-time.
+
The assigned [TileSet].
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index d407509f13e..ab2c663ff66 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -346,7 +346,8 @@ void TileMap::update_dirty_quadrants() {
Color debug_collision_color;
Color debug_navigation_color;
- bool debug_shapes = st && st->is_debugging_collisions_hint();
+ bool debug_shapes = show_collision && (Engine::get_singleton()->is_editor_hint() || (st && st->is_debugging_collisions_hint()));
+
if (debug_shapes) {
debug_collision_color = st->get_debug_collisions_color();
}
@@ -1792,6 +1793,15 @@ String TileMap::get_configuration_warning() const {
return warning;
}
+void TileMap::set_show_collision(bool p_value) {
+ show_collision = p_value;
+ _recreate_quadrants();
+}
+
+bool TileMap::is_show_collision_enabled() const {
+ return show_collision;
+}
+
void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
@@ -1827,6 +1837,9 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_compatibility_mode", "enable"), &TileMap::set_compatibility_mode);
ClassDB::bind_method(D_METHOD("is_compatibility_mode_enabled"), &TileMap::is_compatibility_mode_enabled);
+ ClassDB::bind_method(D_METHOD("set_show_collision", "enable"), &TileMap::set_show_collision);
+ ClassDB::bind_method(D_METHOD("is_show_collision_enabled"), &TileMap::is_show_collision_enabled);
+
ClassDB::bind_method(D_METHOD("set_centered_textures", "enable"), &TileMap::set_centered_textures);
ClassDB::bind_method(D_METHOD("is_centered_textures_enabled"), &TileMap::is_centered_textures_enabled);
@@ -1898,6 +1911,7 @@ void TileMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled,Offset Negative X,Offset Negative Y"), "set_half_offset", "get_half_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_collision"), "set_show_collision", "is_show_collision_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compatibility_mode"), "set_compatibility_mode", "is_compatibility_mode_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered_textures"), "set_centered_textures", "is_centered_textures_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv");
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 13ffb08fae9..ccad07f8118 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -80,6 +80,7 @@ private:
CollisionObject2D *collision_parent;
bool use_kinematic;
Navigation2D *navigation;
+ bool show_collision = true;
union PosKey {
@@ -277,6 +278,9 @@ public:
void update_dirty_quadrants();
+ void set_show_collision(bool p_value);
+ bool is_show_collision_enabled() const;
+
void set_collision_layer(uint32_t p_layer);
uint32_t get_collision_layer() const;