Search Unity

Tile Map Populate tilemap-palette with custom TileBase class?

Discussion in '2D Experimental Preview' started by Kirsche, Aug 29, 2018.

  1. Kirsche

    Kirsche

    Joined:
    Apr 14, 2015
    Posts:
    36
    If you drag a sprite atlas onto the tilemap-palette Unity automatically generates the required tile-assets. However I'd like Unity to use my custom TileBase-inherited class for all tiles, so I can add a few useful properties like SurfaceType.

    Is there anyway to tell Unity to use my custom tile class?
     
  2. BlackHoleTracer

    BlackHoleTracer

    Joined:
    Jan 23, 2014
    Posts:
    1
    Yes, write your class (inherited from TileBase or Tile) and add to code of this class such lines:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. // The following is a helper that adds a menu item to create a MyTile Asset
    3.     [MenuItem("Assets/Create/MyTile")]
    4.     public static void CreateMyTile()
    5.     {
    6.         string path = EditorUtility.SaveFilePanelInProject("Save My Tile", "New My Tile", "Asset", "Save My Tile", "Assets");
    7.         if (path == "")
    8.             return;
    9.     AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<MyTile>(), path);
    10.     }
    11. #endif
    These lines will create new menu item (in Unity Editor) here: Assets->Create->MyTile. Click this and you will get your Tile.

    See Unity example here: https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles-Example.html
    And you can use shorter alternative - CreateAssetMenuAttribute ( https://docs.unity3d.com/ScriptReference/CreateAssetMenuAttribute.html )
     
  3. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    66
    Is there a better solution for this? It seems cumbersome to have to create a new Tile object each time you want to add properties to a new sprite you want to make into a tile, as well as individually drag those new objects into the tile palette.

    Let's say I create a WallTile that has a property that says this tile is impassable. Every time I have a new sprite that represents a wall I would have to create another WallTile scriptable object, add the sprite asset to it, then drag it into the correct tile palette.

    Is there a way to customize the tile palette inspector to assign tile types to tiles already added to the palette?
     
    Last edited: Feb 6, 2019
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    325
    Unfortunately, this is not possible now. We will improve the Tile Palette to have this functionality.
     
    P10tr3k and tgaldi like this.
  5. P10tr3k

    P10tr3k

    Joined:
    Sep 29, 2016
    Posts:
    3
    I'm also looking for that. It would be very nice feature :)