0 votes

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?

in Engine by (304 points)

1 Answer

+2 votes
Best answer

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).

by (7,894 points)
selected by

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.