Custom Tile with Game Object and Without Sprite

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 (), 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;
}
}
}

I found a solution:
Create a second Tilemap for your custom tiles and disable the “Tilemap Renderer”

1 Like

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.

Mate, you’re just pointing at this very same page x)