I can not get the tile to change color during play. Everything other than the SetColor() function works in this code.
Even the Debug.Log(GetColor) gives me the correct color of each tile, but it does not show visually. it is definitely accessing the correct tile, it just refuses to Set Color.
This is the third tilemap in our game, placed on top of the other two.
The TileFlags have been set to “None” both in inspector and in code. Please Help.
Code excerpt:
private void OnGridReady()
{
for (int i = 0; i < Network.allUsers.Count; ++i)
{
User user = Network.allUsers[i];
Grid._instance.tiles[user.cityLocation].owner = user.userId;
Grid._instance.tiles[user.cityLocation].building = 1;
Vector2Int pos = Grid._instance.GetPosition(user.cityLocation);
Vector3Int loc = new Vector3Int(pos.x, pos.y, 1);
PlaceTiles._instance.overlayMap.SetTile(loc, PlaceTiles._instance.buildingTiles[1]);
PlaceTiles._instance.overlayMap.SetTileFlags(loc, TileFlags.None);
PlaceTiles._instance.overlayMap.SetColor(loc, new Color(Random.Range(0.3f, 1), Random.Range(0.3f, 1), Random.Range(0.3f, 1))); // Does not work
UnityEngine.Debug.LogWarning(PlaceTiles._instance.overlayMap.GetTileFlags(loc)); // This actually works
PlaceTiles._instance.overlayMap.RefreshTile(loc);
}
onReady?.Invoke();
}
I’ll apologize if I get this wrong but I suspect it’s the ‘RefreshTile’ after you set the color.
When a tile is added to a Tilemap or refreshed it first runs GetTileData, then GetTileAnimationData, then StartUp.
So if you set the color on the MAP and then REFRESH the tile then the color set in the tile will overwrite (figuratively) the color you just set.
So my best shot would be to remove the refreshtile method call.
Another way to ensure that you don’t have to worry about the flags is to use the SetTiles method that takes a TileChangeData array as a parameter. That method also (IIRC) has a param that lets you ignore flags.
It is also way more efficient if you can pregenerate everything.
public void SetTiles(TileChangeData[] tileChangeDataArray, bool ignoreLockFlags);