How to increase tilemap 2d boundary and draw tiles?

So I want to draw tilemap 2d’s sprite by script while game play. (for example, as per player’s movement on initial finite tilemap)

So for this, need to tilemap’s boundary increase and set tile to newly increased position?
How?

So before game play, I drew manually tilemap sprite just cover the full screen,
Tilemap’s debug.log initial size says (28, 17, 1), origin says (-15, -8, 0)

and I did like,

        Vector3Int newSize = TilemapBase.size + new Vector3Int(3, 0);
        TilemapBase.size = newSize;
        TilemapBase.ResizeBounds();
        TilemapBase.SetTilesBlock(area, BaseTileSprite);

But when play game, tilemap does not increase at all as above code intended.

What is right way to do this?

Hm what is TilemapBase?

The docs say:

Do can you try to set the tiles before calling ResizeBounds()? Did you debug the code to see what happens to the tilemap and size and the content after each step?

public Tilemap TilemapBase;

I thought before I set some tile sprite graphic to cell, first I should enlarge the tilemap’s size.

But this is wrong maybe? Just set sprite is possible?

I just tried it, the Tilemap is growing automatically when you add tiles. See the screenshot, I just log the size, then I add some tiles and log the size again. You can see the green tiles get added just fine.

Code:

public class TilemapExtender : MonoBehaviour
{
    public Tilemap tilemap;
   
    [ContextMenu("Extend")]
    public void Extend()
    {
        Debug.Log(tilemap.size+"-"+tilemap.origin);
      
        TileBase tileBase = tilemap.GetTile(new Vector3Int(0, 0, 0));
        for (int y = 0; y < 20; y++)
        {
            tilemap.SetTile(new Vector3Int(0,y,0), tileBase);
        }
        Debug.Log(tilemap.size+"-"+tilemap.origin);
    }
}
1 Like