Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Suggestions: arbitrary placement of tiles, randomized tiles, cell size per layer, pixel placement

Discussion in '2D Experimental Preview' started by AssembledVS, Aug 24, 2016.

  1. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    There does not seem to be much documentation on these experimental preview features, so please let me know if anything on this list is already included. I have experience with only one other tilemap program, Tiled, which I use with Tiled2Unity to create mesh-based tilemaps. Some of these features are included there.
    • Arbitrary placement of tiles
    You should be able to place any tiles arbitrarily, like any Unity object. This can be very helpful for tiles like loose grass, for example. Instead of having to create two sets of sidewalks - one with grass in between the cracks and one without - the grass can be placed as a separate layer on top of the sidewalk, in any combination. While you can make arbitrarily-placed objects children of a tilemap and become part of larger a large tilemap collider, as far as I can see, there is no way to make these objects actually be part of the tilemap like tiles are part of the tilemap. I would not want a thousand pieces of grass become their own hierarchy objects, even if children of the tilemap.
    • Separate, customizeable grid to aid with arbitrary placement of tiles
    When working in Photoshop, I have a grid with subdivisions that allows me to paint tiles in a consistent style. Similar subdivisions in Unity can help with the placement of arbitrary tiles and even other Unity objects. Beyond subdivisions, however, the grid should be customizable in terms of general size, color, etc. - anything that can help the user in making a map.
    • Pixel-perfect placement of Unity objects, including arbitrarily-placed tiles
    I currently use U2DEX mostly because of its customizable grid and ability to snap to the nearest pixel when placing Unity objects. Most tilemaps I've seen use pixel art, which means that most Unity games employing tilemaps will have pixel art Unity objects as well. Without U2DEX, my 1-pixel-to-unit sprites are placed at non-integer positions like 47.8, etc., and I constantly have to correct it. Perhaps I'm missing something important here, but this seems like a feature that's been long overlooked.
    • Pixel-perfect colliders
    Like above, but with colliders. Edge Colliders are often not pixel perfect, as are Polygon Colliders, etc. If you ever tried editing a Polygon Collider 2D for a sprite object, you will see that it is always too "fine" for pixel art. There is no way to replicate the same Polygon Collider 2D exactly in two different objects via the collider "Edit Mode." In Tiled, I can use the collision editor to make a polygonal collision object with lines that follow the pixel lines of my sprite perfectly, and Tiled2Unity can make that into a pixel-perfect Polygon Collider 2D.

    Every collider's "Edit Mode" should have the ability to edit it per-pixel/integer. For Box Colliders now, it has to be done manually by inputting whole numbers in its size. This is impossible for Edge Colliders or Polygon Colliders, however, and is still a drag with Box Colliders.

    I include this as part of the Tilemap suggestion because most tilemaps are composed of pixel art, and thus most Unity objects will also be pixel art.

    EDIT: I now noticed that polygon and edge colliders have the option of changing their vertices via input of hard numbers (must have been introduced a few Unity versions ago, as the option used to be greyed out for me, or maybe I did something to make the option accessible). This does most of what is necessary for pixel perfect colliders.
    • Randomized tiles with weights
    Tiled lets you select a group of tiles, and when toggling "random," it will select one random tile as a brush instead of all of the selected tiles at once. This is good for painting variations of a tile quickly. A per-tile weight attribute can help with the random function choosing a certain tile more or less often. In Tiled, the default is 1; changing it to 10, for example, will make it 10 times more likely to be chosen.
    • Cell size per layer
    This can currently be worked around via a separate tilemap object with a different cell size, but I'm not sure what the best practices are regarding having multiple tilemap objects in a scene. Essentially, sometimes you have tiles that are different sizes. Personally, I work with 32 x 32 and 16 x 16 tiles, and possibly even more sizes in the future, within the same project. Tiled allows you to input a horizontal and vertical offset per layer, so it is almost as good as having your own different grid size layer.
     
    Last edited: Aug 27, 2016
  2. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Thanks for the awesome feedback. Need to digest it all. For now just a couple of quick answers.

    Randomized tiles - We've provided the ability to create your own brushes and scripted tiles. These are in the demo project. Long term goal is that there will be a collection of these, ours and also community created for specific needs.

    Cell size per layer - Yes, the current workflow is to create a separate tilemap object. A Tilemap always needs a Grid, the "layers" are tilemaps, that follow its parent grid. So if a different grid size is needed, then a new object will need to be created. Current workflow caters to using multiple tilemaps.

    I want to check somethings before replying to the rest. :)

    Oh and apologies for the lack of documentation. A failure on my part. Trying to keep up with the pace of the development. Most of the Tilemap documentation is in the Preview 1 reference guide, if you haven't taken a look at it yet. Hopefully will be getting more info out in the coming days.
     
    Last edited: Aug 25, 2016
    AssembledVS likes this.
  3. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    Thank you for the reply.

    Good to know about the brushes and scripted tiles - I haven't looked into it or the demo project. Using what I know about Tiled, I tried to see if I can just begin building a small tileset and came across some of these issues.

    If using multiple tilemaps is intended, then it's probably good enough. I can imagine running into issues with having to create multiple tilemaps and multiple tilemap colliders that do not share a composite collider. Unless I make one tilemap a child of another? Would this break anything?

    No worries about the documentation - it is preview, and I want a stable release as quickly as possible, even if it means cutting documentation, etc. Where is this Preview 1 reference guide? I found loose things here and there.

    Thanks!
     
  4. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    It's good do the comparison with what you're familiar with and what the expectations are. We do quite a lot of comparative analysis with many different tools and workflows internally and its always great to have more.

    There might be some cases where issues might arise - generally should be fine. That's why the experimental preview so we can hit those problems early and find solutions :D

    The Preview1 reference guide.
    https://drive.google.com/open?id=1fGYUBPJrJknCsYbAl4z3cOP8x6kealwjZfa2DwcXSgA
     
    AssembledVS likes this.
  5. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    Thanks for the link. Of course it was a pinned thread on the front page. The documentation is pretty good for now, actually.

    About pixel perfect colliders - I just noticed that it's now possible to edit the hard numbers of polygon and edge colliders. The option was grayed out in previous versions of Unity (not sure when), or maybe I did something to make the option appear. These hard numbers allow for pixel perfect colliders and works perfectly, although it's still a bit more difficult than dragging in edit mode in a pixel-perfect way.
     
    Last edited: Aug 27, 2016
  6. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    In Preview 2 - You can use the Physics Shape Editor, found in the Sprite Editor to edit the sprites physics shape. This has a snap to pixel mode. This should help in defining the shape to the pixels.
     
    AssembledVS likes this.
  7. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    I just saw that yesterday - this pretty much does everything that's needed, then. Thanks!

    But how does this Physics Shape Editor work? There's no info online or within the documentation. Does it automatically generate a collider or something? I edited the physics shapes of some regular sprites as well as tile sprites, but nothing happens. Added a tilemap collider to a regular sprite and nothing happens, either. Do I need to add a certain kind of collider? And am I doing it right? I edit the shape and hit apply?
     
    Last edited: Aug 28, 2016
  8. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    It does not generate a collider. You will need to put a 2D collider manually. If for a TileMap, use the TileMapCollider2D and CompositeCollider2D. If on a Sprite, use the PolygonCollider2D.

    In the Demo Project (PreviewR201) Check out the TileMapExample03 there is a set of tiles that make use of the Physics Shape. You can also check out the sprite itself '
    '
     
    AssembledVS likes this.
  9. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    This works for a single sliced sprite with a Polygon Collider 2D, but not a painted tile with a tilemap collider 2D. It works in the demo, however. Following the demo exactly in my own project does not generate a collider when working with a tilemap.
     
  10. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    I can confirm that it works in my project. Make sure your tile asset has the collider type set to "sprite" and it will use the shape you have set on the sprite. And for the tile map collider to work, make sure you also have a composite collider with a static rigid body, and check the "use composite collider" box on your tile map collider. It should work. You can update the tile map collider by disabling it and enabling it again.
     
    AssembledVS likes this.
  11. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    Thank you. As far as I can tell, everything is as you suggested.

    Here is an image showing my setup.

    If I throw one of the sprites from my spritesheet into the scene and add a polygon collider 2D, it works then. But not when part of a tilemap with a tilemap collider.
     
  12. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Seems to be an issue related to the Grid cell size. The one on the left Cell size is 16,16,1. The one on the right is 1,1,1.
    upload_2016-8-31_8-33-29.png
     
    AssembledVS likes this.
  13. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    Yes, you're right. I think that this comes back to me using 1 px = 1 unit. When changing the grid to 1,1,1, the tilemap becomes distorted, but the collider, also distorted, at least exists.