Tilemap.SetColor problem

Hi guys,

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

Solved. In default, the color is locked. Setting the TileFlags to none helped.

4 Likes

would you post setFlags code, please? I tried but not works.

public void DrawTile(Coord coord, MapLayer layer, string tileName, Color? color = null)
    {
        if (TileMapDic.ContainsKey(layer))
        {
            TileMapDic[layer].SetTile(new Vector3Int(coord.X, coord.Y, 0), TileDB.GetTile(tileName));

            //if (color !=null){
            TileMapDic[layer].SetTileFlags(new Vector3Int(coord.X, coord.Y, 0), TileFlags.None);

            TileMapDic[layer].SetColor(new Vector3Int(coord.X, coord.Y, 0), Color.blue);


            TileMapDic[layer].RefreshTile(new Vector3Int(coord.X, coord.Y, 0));
        }
        else
        {
            throw new Exception("there's no layer : " + layer);
        }
    }

Hey did you end up working it out? I’m having the same trouble.
Tried what was suggested above too but no result.

Used this code

tileMap.SetTileFlags(location, TileFlags.None);
tileMap.SetColor(location, Color.black);
1 Like

I’m having the same problem here. I can’t get SetColor to work, even after setting tileflags to none. Any idea what I’m missing?

Thanks - SlapworthFH

UPDATE: I figured it out… or rather, I realized I was having the problem described and solved here: Color of a tile - Tilemaps Unity 2017.2

I had to select the tile in the tile palette, AND set the inspector into Debug mode, so I could stop the tile from locking color.

1 Like

how to solve this if i dont use a palette?
i just create the tiles by code

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:

            tilemap.SetTile(coordinate, myTile);
            tilemap.SetTileFlags(coordinate, TileFlags.None);
            tilemap.SetColor(coordinate, myTileColor);

Hope this helps someone!

3 Likes

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.

1 Like

Thanks, HuldaGnodima!

1 Like

I just had this issue in Unity 6 preview. As mentioned above, I needed to set tileflags to none. I didn’t need to use refreshtile though.

TM_Ground.SetTileFlags(gridLocation, TileFlags.None);
TM_Ground.SetColor(gridLocation, newColor);

Yay! This helped a lot!