Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

1 Tilemap vs Many Tilemaps

Discussion in '2D' started by GazingUp, Jan 22, 2021.

  1. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    The 3/4 perspective game I am working on sorts everything on the Y and Z axis. I have the issue of displaying the player what's behind 'higher objects' and 'walls' that obscure the camera.

    I explored the many options of shaders, none which would work for the visual look and feel I'm going for. Or maybe I'm not good with shaders. I'd played around with transparency on the material of the tilemap and on trigger, I can tweak this transparency to show what's behind certain objects. This works fine.

    However - my game has fake height and a jump mechanic all over, and initially I had thought of using just one tilemap for one height level. But if I use just one tilemap, changing the transparency on trigger changes transparency of all the tiles in that tilemap (which can be separated across the scene).
    My solution to this was to break up the tilemap into multiple smaller chunks of tilemaps across one scene.
    So instead of height_3 => High_Ground, it would be height_3 => High_Ground_1, High_Ground_2 etc...

    Is this a performant approach? I do intend on limiting my scenes to contain chunks of tilemaps - doesn't Unity handle what's in the camera view and batch the rest? Definitely not planning on having hundreds of tilemaps in one scene. Maybe around 50-60 max. It would be definitely helpful to know if I'm on the right track here as it would be really easy on the code and design. Thank you.
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    50-60 might be fine however its much worse performance than 1 tilemap

    use the Z coordinate to set tiles at different heights

    change the transparency of the tiles you want and not the tilemap renderer

    then use tilemap.settile to overdraw the tiles you want to be transparent
     
  3. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    I found that trying to use multiple tilemaps was a non-starter for my game, although it might be okay for you. The problem I had was that there was multiple mobiles and as such different maps may need to be both above and below at the same time. If you only have 1 mobile though this shouldn't be an issue.

    What I did Instead is fiddling with the Z coordinate of my mobiles as they move and just relying on the natural sorting of the tilemap with the appropriate custom sort axis and that has pretty much solved the issue. While there was a lot of time wasting figuring out the exact fiddle I needed, the final script logic is pretty straight forward and easy. Basically you figure out if the sorting point is in the upper half of the 'floor' or lower half of such, and adjust the Z but +1 or 0 appropriately. A more complex version even allowed me to have pretty good ramps that actually properly adjust the Y coordinate as you move but that was considerably more complicated.
     
  4. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    Does tilemap.setTile have the ability to change the color/alpha of a specific tile in the tilemap? Or would that be setColor? I want it to be a smooth transition into a transparent look. I think setTile will instantly change the tile to a transparent one
     
  5. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    Just tried the SetColor method. It only changes the transparency of specific tiles the GO is on. I want the specific area that's bound by the polygon collider to become transparent without making other tilemaps in the scene transparent. It'd be weird just showing a very small area around the player and not the rest.
    Essentially the way I was asking to use tilemaps was the same way you'd use GameObjects, except Tilemaps make it a lot easier to design levels and collision (as well as the z-coordinates for sorting.)
     
  6. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    What did you mean by mobiles?
     
  7. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    yes it has

    you first do tile.color,a = 50 ( for example )

    then you do tilemap.settile( pos, tile )

    if you want smooth then do this process by starting with a = 250 then settile, then a = 200 then settile, basically you are lowering the transparency step by step
     
  8. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    Anything that moves between tiles (usually things like the player character, monsters, etc). If you're doing a kind strategy RPG movement where your characters are only ever on percisely a tile, that's different as standard tile sorting should work for them. It is only when they are not percisely on a tile at all times that you get into sorting issues.
     
  9. GazingUp

    GazingUp

    Joined:
    Jun 16, 2015
    Posts:
    271
    I don't have sorting issues though. Sorting's fine as that has to do with the sprite/tiles' sort pivots and the z coordinates accordingly. I was talking about when a player is in the lower ground, and walks under a high ground, the player should be able to see themselves so making that high ground tilemap transparent does the trick!
     
  10. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    Okay, yeah, if you only need such for the player, that should be okay. Another possibility would be to have 2 overlapping instances of your player sprite, one transparent but above all the tilemaps, and one sorted normally but opaque. Haven't tried it though, but might be more efficient if it looks right, but got a feeling the overlap even with identical sprite may do weird stuff.