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

Custom Tile with Game Object and Without Sprite

Discussion in '2D Experimental Preview' started by thekendocat, Mar 9, 2017.

  1. thekendocat

    thekendocat

    Joined:
    Feb 15, 2017
    Posts:
    1
    Hi,
    Thank you for the 2d preview builds. It's really fascinating to work with the new tools.
    Yesterday I created a custom terrain tile to determine edges and it worked very well.
    Today I tried to create a new tile for placing gameObjects (like collectibles and traps) but it's not working. Seems there is a difference when Sprite is null and GetPreview is linked to a sprite. Even Tile Palette doesn't show the tile but when I change the Sprite from null to m_preview it works. How can I change it to support showing the GameObject and no Tile in level?

    Best Regards

    namespace Game.Tile
    {
    [Serializable]
    public class GameObjectTile : TileBase
    {
    [SerializeField]
    private GameObject m_gameObject;

    [SerializeField]
    private Sprite m_preview;


    #if UNITY_EDITOR
    [MenuItem ("Assets/Create/Game Object Tile")]
    public static void CreateTerrainTile ()
    {
    string path = EditorUtility.SaveFilePanelInProject ("Save Game Object Tile", "New Game Object Tile", "asset", "Save Game Object Tile", "Assets");

    if (path == "")
    return;

    AssetDatabase.CreateAsset (ScriptableObject.CreateInstance<GameObjectTile> (), path);
    }

    public override Sprite GetPreview ()
    {
    return m_preview;
    }
    #endif

    public override bool GetTileData (Vector3Int position, ITilemap tileMap, ref TileData tileData)
    {
    UpdateTile (position, tileMap, ref tileData);
    return true;
    }

    private void UpdateTile (Vector3Int position, ITilemap tileMap, ref TileData tileData)
    {
    tileData.sprite = null;
    tileData.gameObject = m_gameObject;
    }
    }
    }
     
  2. Wicked0815

    Wicked0815

    Joined:
    Jan 15, 2018
    Posts:
    1
    I found a solution:
    Create a second Tilemap for your custom tiles and disable the "Tilemap Renderer"
     
    CheekySparrow78 likes this.
  3. ink13

    ink13

    Joined:
    Nov 14, 2013
    Posts:
    37
    Someone had a similar problem over here, if you disable the tilemap renderer component you'll get the functionality you're after without sprites appearing in the gameview.
     
  4. WegPast

    WegPast

    Joined:
    Aug 29, 2017
    Posts:
    2
    Mate, you're just pointing at this very same page x)