The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

Hi everyone, i was wondering if there was a way to iterate my cells in a tilemap and detect which cells are empty?

I have created a town and would like to spawn enemies randomly but in not occupied tiles in a tilemap.

Any help is very much appreciated!

Love the engine! being trying it out for the past 4 days and i just love it!

enter image description here

in Engine by (13 points)

1 Answer

+1 vote

You either create a singleton and an array of collision tile id's and check it with array.has(val), which is what most games do, or you create two separate TileMaps, one for collision, the other for non-collision. Then it's pretty simple, just spawn monsters on tiles with id -1 on the collision TileMap.

by (1,118 points)

Godot have a constant for invalid cell in TileMaps.

INVALID_CELL = -1 — Returned when a cell doesn’t exist.

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 Frequently asked questions and 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 [email protected] with your username.