Search Unity

The tilemap does lack documentation

Discussion in 'Documentation' started by rainboww, Mar 2, 2019.

  1. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    This is an example of really bad documentation.

    https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles.html

    First: For what is it good, what can you actually do with it.
    Then: Examples there are only lines of code with nearly no description of the context you use them in.
    And last: a comprehensive tutorial what you can do with it. If there is one somewhere it should be linked.

    For me i would like to generate a tilemap from a script. I have no where in the internet found how to do this at all. I did not even find a good tutorial on how to place a tile from a script.
     
    Last edited: Mar 2, 2019
  2. Sam_Ooi

    Sam_Ooi

    Unity Technologies

    Joined:
    Mar 5, 2018
    Posts:
    61
    Hello, I'm sorry for your frustration about the documentation. Please note that the page you are referring is specifically about Scriptable Tiles (example projects are publicly available on the 2D-extras and 2D-techdemo repos which are linked from the Tilemap page). For the general Tilemap scripting API, please refer to the script reference pages for Tiles and Tilemaps. The Tilemap.SetTile and Tilemap.SetTiles pages should provide the example scripts you are looking for.

    We also have 2 blog posts about creating procedural Tilemaps with examples, available here: Part 1 and Part 2.
     
  3. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    Hello UnitySamO,
    I looked into 2D-techdemo, the reference and now also your procedural tilemap examples.

    However i would like to create a tilemap from a folder of sprites and none of this does come even close to describe how to assign sprites to tiles with scripts.
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    I guess there is no explicit example which creates a Tilemap procedurally. All the bits and pieces come from different parts of the manual and scripting reference.

    Retrieving Sprites from a Texture:
    Resources/Asset Bundles, Addressables
    Code (CSharp):
    1.  
    2. var sprites = Resources.LoadAll<Sprite>(myTexturePath);
    3.  
    Creating a Tile asset:
    ScriptableObject, Tiles
    Code (CSharp):
    1.  
    2. var tile = ScriptableObject.CreateInstance<Tile>();
    3. tile.name = myTileName;
    4. tile.sprite = myTileSprite;
    5. tile.color = myTileColor;
    6. AssetDatabase.CreateAsset(Tile, tilePath); // If in UnityEditor
    7.  
    Setting a Tile on a Tilemap:
    Tilemap.SetTile
    Code (CSharp):
    1.  
    2. tilemap.SetTile(position, myTile);
    3.  
     
  5. Meneliki_

    Meneliki_

    Joined:
    Feb 7, 2020
    Posts:
    10
    Is there a way to retrieve custom data from an individual tile?

    Something simple like:

    Code (CSharp):
    1.  
    2.  
    3. //please make this happen
    4. myVariable = tilemap.GetTile(someVectorPosition).MyCustomProperty;
    5.  
     
  6. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    You will need to specify the Type of your Tile:

    Code (CSharp):
    1. var myData = tilemap.GetTile<MyCustomTile>()?.customData;