Search Unity

Tilemap Frustrum Culling

Discussion in '2D' started by delinx32, Jul 6, 2019.

  1. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    I have some code that fills a 20x20 tilemap with tiles. When I do this through scripting the tiles aren't culled outside of the camera's frustrum and there are 400 batches/setpass calls. When I do it through the tile map palette they are. Is there something that has to be set on the Tile object that enables culling?
     
  2. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    now that I'm at a computer I can post the code:

    Code (CSharp):
    1.                 RoomSprite = Sprite.Create(texture, new Rect(0, 0, tSize.x, tSize.y), new Vector2(.5f, .5f), s.pixelsPerUnit, 1, SpriteMeshType.Tight, Vector4.zero, true);
    2.  
    3.                 RoomTile = ScriptableObject.CreateInstance<Tile>();
    4.                 RoomTile.sprite = RoomSprite;
    5.                 RoomTile.colliderType = Tile.ColliderType.Sprite;
    6.                 RoomTile.name = name + "_roomTile";
    So, I'm building a texture and creating a sprite from it, then creating a tile from that. My Batches show 2 (saved by batching 398). I can't figure out what this is doing differently than painting the tile using the tile palette. I'm just setting the tile using TileMap.SetTile(), so there isn't really anything to that.
     
  3. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    After some more testing it seems the behavior I'm seeing is consistent with the tile palette, so all good I guess.