How to get_cell_by_id in a 3d grid map?

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

Hi All.
In 2d tile map there is this method get_cell_by_id which returns all cells of an index in an array. Is there something similar for 3d tile maps? I want to be able to capture all tiles of a particular ID so that I can add a child to each. How can I do that?

:bust_in_silhouette: Reply From: Zylann

There doesn’t seem to be such function in GridMap. You’ll have to write it yourself. Here is a helper function you could use (not tested):

static func get_cell_by_id(grid_map: GridMap, wanted_item: int) -> Array:
	var used_cells = grid_map.get_used_cells()
	var results = []
	for cell_position in used_cells:
		var item = grid_map.get_cell_item(cell_position.x, cell_position.y, cell_position.z)
		if item == wanted_item:
	return results

thanks, reads like it should work, i’ll try it out tonight:)

Macryc | 2020-04-21 13:46

Worked a charm!!

Macryc | 2020-04-21 20:10