I’m asking for a help with Tilemap.setColor. I can’t make it working. I have no idea what’s wrong. For example, I want to change from white to red but, as you can see from the debuging screenshot, it’s not happening. The color stays white; r = 1, g = 1, b = 1.
I appreciate any help.
Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class TermalTileMap : MonoBehaviour {
[SerializeField]
private TileBase[] tileBase;
private Tilemap tileMap;
private float[,] blockTempDataMap = new float[250, 150];
void Start ()
{
tileMap = GameObject.Find("TermalTileMap").GetComponent("Tilemap") as Tilemap;
for (int y = 0; y < blockTempDataMap.GetLength(0); y++)
{
for (int x = 0; x < blockTempDataMap.GetLength(1); x++)
{
tileMap.SetTile(new Vector3Int(y, x, 0), tileBase[0]);
tileMap.SetColor(new Vector3Int(y, x, 0), Color.red);
}
}
}
Did you ever figure it out? I’m in the same boat right now.
Edit: I figured it out and will write here if someone else finds this thread!
I thought I couldn’t get it to work by using the “tilemap.SetTileFlags()” function via code, but it seems you have to call the “tilemap.SetTileFlags()” AFTER setting down the tile (not before), and then call “SetColor” last (I had called SetTileFlags before SetTile).
It seems this is because SetTile can override whatever flags are on the coordinate already, so SetTileFlags should in that case be called afterwards. I got it to work like this:
You could derive a new class of tile from TileBase which by default has permissive TileFlags setting. That would mean you don’t need to SetTileFlags at all.