Skip to content

Commit

Permalink
Merge pull request #88105 from AThousandShips/tile_duplicate_fix
Browse files Browse the repository at this point in the history
Fix duplicating/copying `TileMap`
  • Loading branch information
akien-mga committed Feb 12, 2024
2 parents 24bd307 + 85d9c23 commit 821bf4b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void TileMap::add_layer(int p_to_pos) {
TileMapLayer *new_layer = memnew(TileMapLayer);
layers.insert(p_to_pos, new_layer);
add_child(new_layer);
new_layer->force_parent_owned();
new_layer->set_name(vformat("Layer%d", p_to_pos));
move_child(new_layer, p_to_pos);
for (uint32_t i = 0; i < layers.size(); i++) {
Expand Down Expand Up @@ -538,6 +539,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
if (layers.size() == 0) {
TileMapLayer *new_layer = memnew(TileMapLayer);
add_child(new_layer);
new_layer->force_parent_owned();
new_layer->set_name("Layer0");
new_layer->set_layer_index_in_tile_map_node(0);
new_layer->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileMap::_emit_changed));
Expand All @@ -563,6 +565,7 @@ bool TileMap::_set(const StringName &p_name, const Variant &p_value) {
while (index >= (int)layers.size()) {
TileMapLayer *new_layer = memnew(TileMapLayer);
add_child(new_layer);
new_layer->force_parent_owned();
new_layer->set_name(vformat("Layer%d", index));
new_layer->set_layer_index_in_tile_map_node(index);
new_layer->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TileMap::_emit_changed));
Expand Down

0 comments on commit 821bf4b

Please sign in to comment.