Hi all, I’, trying to top down game with 64x64 tiles and put some decoration that is taller than the tile, for example the ghost in the middle, it’s about 64x128.
I have a Ground tile which is 64x64, and i want to paint the Tree with 64x128 with Prefab brush because i wanted to animate the whole tree.

there are 2 problems that i’m facing now:
- When i paint on the tile, seems like the Tree has a weird offset
- When i want to paint the Tree above Ground, it’s hidden behind the Ground.
Here is my tree

I’m not sure this is the right way to do but I’m running out of idea now.
i am not sure it is the best way but i got this working by making a SplitBrush and SplitBrushEditor
to draw two tiles next to each other on different layers (maps) so the character can walk behind the top of the ‘tree’

using UnityEditor;
namespace UnityEngine.Tilemaps
{
[CreateAssetMenu]
[CustomGridBrush(false, true, false, "Split Brush")]
public class SplitBrush : GridBrush
{
public TileBase Back;
public string BackName = "Back";
public Tilemap BackTilemap;
public Vector2Int BackOffset;
public TileBase Fore;
public string ForeName = "Fore";
public Tilemap ForeTilemap;
public Vector2Int ForeOffset;
public override void Paint(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
{
if (BackTilemap != null && ForeTilemap != null)
{
var bp = new Vector3Int(position.x + BackOffset.x, position.y + BackOffset.y, position.z);
BackTilemap.SetTile(bp, Back);
BackTilemap.SetTransformMatrix(bp, Matrix4x4.identity);
var fp = new Vector3Int(position.x + ForeOffset.x, position.y + ForeOffset.y, position.z);
ForeTilemap.SetTile(fp, Fore);
ForeTilemap.SetTransformMatrix(fp, Matrix4x4.identity);
}
}
public override void Erase(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
{
if (BackTilemap != null && ForeTilemap != null)
{
var bp = new Vector3Int(position.x + BackOffset.x, position.y + BackOffset.y, position.z);
BackTilemap.SetTile(bp, null);
BackTilemap.SetTransformMatrix(bp, Matrix4x4.identity);
var fp = new Vector3Int(position.x + ForeOffset.x, position.y + ForeOffset.y, position.z);
ForeTilemap.SetTile(fp, null);
ForeTilemap.SetTransformMatrix(fp, Matrix4x4.identity);
}
}
}
}
using System.Linq;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace UnityEditor
{
[CustomEditor(typeof(SplitBrush))]
public class SplitBrushEditor : GridBrushInspector
{
private SplitBrush Brush => target as SplitBrush;
public override void PaintPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
{
var b = Brush;
var maps = brushTarget?.transform.parent.GetComponentsInChildren<Tilemap>();
for (var i = 0; i < maps.Length; i++)
{
var map = maps[i];
var name = map.name;
if (name == b.BackName)
{
var p = new Vector3Int(position.x + b.BackOffset.x, position.y + b.BackOffset.y, position.z);
map.SetEditorPreviewTile(p, b.Back);
map.SetEditorPreviewTransformMatrix(p, Matrix4x4.identity);
b.BackTilemap = map;
}
else if (name == b.ForeName)
{
var p = new Vector3Int(position.x + b.ForeOffset.x, position.y + b.ForeOffset.y, position.z);
map.SetEditorPreviewTile(p, b.Fore);
map.SetEditorPreviewTransformMatrix(p, Matrix4x4.identity);
b.ForeTilemap = map;
}
}
}
public override void ClearPreview()
{
var b = Brush;
if (b != null)
{
if (b.BackTilemap != null)
b.BackTilemap.ClearAllEditorPreviewTiles();
if (b.ForeTilemap != null)
b.ForeTilemap.ClearAllEditorPreviewTiles();
}
}
public override GameObject[] validTargets
{
get
{
var brush = Brush;
var list = from map in GameObject.FindObjectsOfType<Tilemap>()
where (map.gameObject.name == brush.BackName) || (map.gameObject.name == brush.ForeName)
select map.gameObject;
return list.ToArray();
}
}
}
}