Hello everyone. I spent quite a while on this problem and it's starting to bug me out. It's not crashing the game or anything, just a little annoying, but the basic gist of it is that I have a custom tile with associated game object:
public class GrassTile : TileBase
{
public GameObject tileGameObject;
public Sprite sprite;
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
tileData.gameObject = tileGameObject;
tileData.sprite = sprite;
}
}
So far so good, and here's the script for the tile object itself:
public class GrassTileObject : MonoBehaviour
{
private GameObject _objectOnTile;
private Tilemap _tilemap;
private void Start()
{
_tilemap = FindObjectOfType<Tilemap>();
}
public GameObject ObjectOnTile => _objectOnTile;
public void SetObjectOnTile(GameObject objectOnTile)
{
_objectOnTile = objectOnTile;
}
private void OnDestroy()
{
_tilemap.SetTile(_tilemap.WorldToCell(transform.position), null);
}
}