Tilemap.BoxFill not filling correctly

So I have a tilemap that already has tiles on it. What I want is to clear it all out and create a solid rectangle of one tile, with which the rest of the monobehaviour will ‘carve out’ to create a cave complex.

So in the Start() of a component I added to a game object with a tilemap, I only have this:

tilemap.BoxFill(Vector3Int.zero, wallTile, -mapSize, -mapSize, mapSize, mapSize);

Let’s say mapSize is 8, and “tilemap” is a reference to a Tilemap that previously had some tiles on it. I expect to see all the prior tiles removed, and a new filled area of “wallTile” that goes from -8,-8 to 8,8

Instead I get a single tile at 0,0,0 and that’s it.

If I leave out the ClearAllTiles(), it does nothing; the old tiles remain, and no new tiles are placed at all. The only way it seems to do anything is if the tilemap was empty before in the scene, but I need to work with a tilemap that was previously in use.

Any suggestions on what I’m doing wrong?

So turns out the tilemap’s bounds were being reset to nothing. Any attempt to fill outside of the bounds will fail, and trying to fill on top of a cell that’s got a tile will also fail.

The work-around was to clear the tiles, place a tile at the upper left and bottom right of the area I was going to fill ( which would resize the bounds). Then I could box fill the tilemap. There doesn’t seem to be a way to enlarge the bounds of the tilemap any other way.

I know it’s been a while since this question was asked but it just came up in my search and I found a different solution for it. ClearAllTiles resets the bounds as mentioned. The correct way to resize the bounds seems to be setting the origin and size and then calling ResizeBounds() on the tilemap.

For example:

groundTilemap.origin = Vector3Int.zero;
groundTilemap.size = new Vector3Int(200, 50, 1);