Search Unity

TileMap - SpriteMask behaviour (Saving batches)

Discussion in '2D' started by pikminscience, Jun 14, 2020.

  1. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    36
    I have a set of tiles within a TileMap that require SpriteMasks to cover a custom range.

    Making prefabs and placing these tiles within the TileMap doesn't allow Chunk mode rendering (batch count skyrockets!).

    Creating a custom shader and placing it on the TileMap (not using prefabs in this scenario - directly painted tiles) works with everything but the custom range (i.e. 'Default' layer range 5-6 of sprite order for example). I've found nothing that replicates the SpriteMask range for this in a custom shader.

    The only other thing I can think of is grabbing the tiles from the tilemap if painted on directly. Shoving these grabbed tiles in to an image, converting it to a sprite and assigning it to a SpriteMask component.

    I'm probably overthinking it but having a hard time finding anything to help me with it and feel like I might be creating a more demanding task rather than living with the huge batch count.

    In summary; I want to run a tilemap with chunk mode rendering with a SpriteMask set to a custom layer and range.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Could you share a screenshot of what you are expecting? That would help in our understanding of this!

    I presume that you would want a SpriteMask that masks certain Tiles within a single Tilemap?
     
  3. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    36
    A SpriteMask that would attach to a tilemap, take its final full tile render and place it in a SpriteMask (adhering to custom range found on the SpriteMask component)


    I'm trying to show off how the sprite masks work on each tile (tiles being gameobjects in this instance). However they run the batch count high.

    My solution currently (doesn't work with order in layers - which is what I'm after):



    So instead of each Sprite/Tile having a SpriteMask I provide a material that functions as a mask instead.

    Everything works as intended (I could even ditch the sprite renderer in this scenario and draw via the tiles in the tilemap and set the TilemapRenderer material to the one above).

    The issue is that if any sprite renderer that has a mask interaction of 'Visible Inside Mask' or 'Visible Outside Mask' goes over this, regardless of its layer; it will interact.

    The SpriteMask component is a work around to this (as shown in the GIF) - I can add one to every SpriteRenderer (so each tile effectively). This however throws the batch count super high.

    I guess in some way the bigger issue is that I can see no way to get a custom stencil shader to play along with other SpriteMask components and sprite renderers (I use them elsewhere; all adhering to different layers dynamically - the workflow ends up being good!).
     
    Last edited: Jun 17, 2020
  4. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    36
    Cleaned up my post - realised it was very confusing.
     
  5. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    If I understand correctly, you would like the rendered Tilemap to act as a mask for a SpriteMask to be used on other Renderers?
     
  6. pikminscience

    pikminscience

    Joined:
    Mar 26, 2019
    Posts:
    36
    Yeah - sorry if the replies are convoluted.
     
  7. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Thanks for confirming! We do not support this right now unfortunately. We'll add this to our feature backlog for consideration.
     
  8. Deleted User

    Deleted User

    Guest

    Have you guys considered this yet or still plan to consider this? A tilemap mask component would be very useful for me, and I would imagine for many others as well.
     
  9. h765643729

    h765643729

    Joined:
    Jan 17, 2018
    Posts:
    21
    It is important when implementing Windows and doors on walls with Isometric Tile.