So I am doing a map generator, when the player reaches certain x position a tilemap is loaded and another is distroyed I use the following code to do this:
func _on_createa2_body_entered(body):
print("create")
total_distance = total_distance + 1024
var new_tile = TileMap1.instance()
new_tile.position.x = total_distance
tiles.push_back(new_tile)
#Here I add the instance to the tree
get_tree().get_root().get_child(0).get_node("Tiles").add_child(new_tile)
pass
func _on_destroya2_body_entered(body):
print("destroy")
var arreglo = tiles.pop_front()
#Here I remove the node
arreglo.queue_free()
pass
For some reason the games slowdown, I read into object pooling but some dev a time ago said that was not necessary in godot so I dont know what to do.