I want to spawn instances of an actor at a random point on a tile map and make sure to spawn it on another tile when the tile is already filled by an object
Array map the tiles. When you spawn something on a tile, remove tile from the array.
To choose a tile random from array.
How can I remove the tile from the array ?
And do I have to create Index of every tile ?
How can I array map the tiles ?
depends solely on your design.
If I did it I’d have a manager class that handled spawning and setting the tiles. Each time I spawned a tile I’d store a reference of it in an array. So var Tiles (tile actor obj ref)[array].
I’d then use a function to choose a rand tile, set a local reference for the tile, remove the index from array, do whatever, then return.
If you aren’t using actors for your tiles, then you need to come up with a way to id and reference each grid cell. Use that reference as your array value.
The only other way is to loop through your tiles and check each to see if it has something. Not performant at all.
I’m using a tilemap, I don’t know how to reference each grid cell. I think it would be the easiest way to do what I’m doing


