Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 1.25 KB

File metadata and controls

26 lines (20 loc) · 1.25 KB

UnityTilemapMask

Works like SpriteMask, but made specifically for Tilemaps.

Preview

alt text

How to use

  1. Download the latest version.
  2. Copy it into your project's Assets folder.
  3. Add the TilemapMask component to the GameObject that contains your Tilemap.
  4. Press Generate Mask.
  5. For any SpriteRenderer that should only appear inside the mask, set Mask Interaction -> Visible Inside Mask.
  6. Done! :)

Notes:

  • Make sure your SpriteRenderers have a higher Order in Layer than the Tilemap. Otherwise, they may not appear at all.
  • Whenever you modify the Tilemap, you need to regenerate the mask:
    • Use the Generate Mask button, or
    • Call TilemapMask.GenerateMask() at runtime.
  • If you don't want to think about it, just call it once on game start.

How it works

  • The component iterates through all tiles, puts individual SpriteMask objects on their positions, and copies their sprites to use as masks. This approach is simple and works well in most cases. For really large tilemaps, I guess, object pooling or smth like that could be added to improve perfomance.