Search Unity

Feedback Tilemap API requests

Discussion in '2D' started by Lo-renzo, Nov 16, 2020.

  1. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Problem
    For maximum control and flexibility, I set as much of a cell's TileData externally rather than overriding TileBase's GetTileData() and other methods. Right now, the API lacks good options for fully controlling the TileData properties at once. It requires several API calls to, for example, set the tile, color and matrix.

    The problem is even worse when it comes to the more performant methods: SetTiles / SetTilesBlock. These methods are so much more performant that I queue up all calls to ensure I use these methods exclusively. However, the API likewise lacks performant methods that allow changing both the tile and then setting the color / matrix in one call. This, then, requires an awkward system of splitting off those color/matrix changes, and executing those changes after the tile has been set by SetTiles. It would be much better if only 1 call were necessary for setting cell, tile, color, transform information at once.

    A few more methods would better allow Tilemap users to have maximal efficiency and versatility when writing to it.

    Context
    I have a building game. I found it much better to allow setting color and rotational / matrix data externally - not from within overridden methods of some child class of TileBase. This allows me to have a JSON file define how a tile looks rather than many different tiles.

    Proposed changes for Tilemap
    struct TileChange
    With fields Vector3Int, TileBase, Color, Matrix4x4 and maybe TileFlags.
    Any field on TileData that would be safe to change at once would be on this struct.


    void SetTile(Vector3Int cell, TileBase tile, Color color, Matrix4x4 transform)
    void SetTile(TileChange change)
    void SetTiles(TileChange[] changes)
    above is a cleaner equivalent of: SetTiles(Vector3Int[] cells, TileBase[] tiles, Color[] colors, Matrix4x4[] transforms)

    Finally, we could really use non-allocating versions of SetTiles for both existing and proposed methods.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    This sounds fair! We will look into exposing this as well as making them non-allocating if possible too.

    If there are other API requests, do let us know as well!
     
    Lo-renzo likes this.
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Vector3Int v3i = new Vector3Int(x, y);


    This constructor, like Vector3's equivalent, would be convenient when working with the tilemap when z is not in use.
     
    Last edited: Jan 13, 2021
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Sounds good, we will consider this as well!
     
    Lo-renzo likes this.
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    THANK YOU! <3 <3 <3
    https://unity3d.com/unity/alpha/2021.2.0a8
     
    ChuanXin likes this.