How can I get the unused cells or the size of a GridMap (3D)?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By henriquelalves
:warning: Old Version Published before Godot 3 was released.

I was just wondering if there is a way to get the unused cells of a GridMap or its total size, because in 2D I usually create TileMaps to make Level Design easier (by creating a separate script that converts each tile in the child node that corresponds to said tile); in 3D I have no idea how to do the same thing using a GridMap. What I’m doing right now is just setting a “manual” size of the whole level, and I’m updating it accordingly each time I change the Grid. Is there a better way?

:bust_in_silhouette: Reply From: eons

The number of unused cells is infinite (or size of int^3) minus used cells… ^_^;

No, I don’t think there’s a way to know that (in general, 3D is weird when talking about size of things).

So your solution may be the best/quick/cheap way.
Every time you add a cell, max and min check x,y,z adding it to a pair of Vector3 or individual variables.

With that “extent” you keep, you can iterate over all the cells and get the internal ones that are unused (-1) with get_cell_item.


One day, GridMap may get more features like TileMap, something like get_used_cells could be handy (you are free to make a request on GH).

I see, thanks! I guess I should make a request on GH, since this type of thing is very useful in the workflow me and other people are used too.

henriquelalves | 2016-12-07 22:57