How do I delete an object and it's mesh frm an array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fase45

I have tiles stored in an array like this:

	road_dificulty = ((randi() % road_type.size()))
		
	var new_road = road_type[road_dificulty].instance()
	tile_list.push_back(new_road)
	add_child(new_road, true)
	new_road.translation = Vector3(0, 0, 1) * spawn_z
	spawn_z += tile_legnth
	old_road = road_dificulty

I am trying to remove the first mesh added in the array so that I can get better performance and stop rendering it.

I tried:

        var first_tile = tile_list.front()
        first_tile.queue_free()

that didtn’t work. So I’m still unsure how to free the remove the object from the array because the mesh is still there when I run this code

:bust_in_silhouette: Reply From: Zylann

It is still there because you did not remove it from the array. You only destroyed the node.
Use tile_list.pop_front() to remove the front tile as well:

var first_tile = tile_list.pop_front()
first_tile.queue_free()

Thank you that worked!

fase45 | 2020-05-26 17:14