Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question TileMap.SetTile not working :(

Discussion in '2D' started by LazyGhost15, Oct 6, 2023.

  1. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    88
    So I made a script that gets the color of the pixel in the texture2D, and then it places the color at the tile by order, I used some debugging and it looks like it goes through every stage and just the SetTile isn't working, It has the color and the location of the tile. The script:

    Code (CSharp):
    1.  Color Pcolor = PNGMap.GetPixel(x, z);
    2.         print(Pcolor.a);
    3.         if(Pcolor.a == 0)
    4.         {
    5.             print("No Color");
    6.             return;
    7.         }
    8.         else
    9.         {
    10.             print("The Last Step");
    11.             TMap.SetColor(new Vector3Int(x, 0, z), Pcolor);
    12.         }
    13.     }
    The TIleMap is in XZ Orientation if that matter in some way
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Try resetting all the flags:
    Code (CSharp):
    1. var pos = new Vector3Int(x, 0, z);
    2.  
    3. TMap.SetTileFlags(pos, TileFlags.None);
    4. TMap.SetColor(pos, Pcolor);
    If that works, you can unlock only the color flags with:
    Code (CSharp):
    1. var pos = new Vector3Int(x, 0, z);
    2.  
    3. TMap.SetTileFlags(pos, TMap.GetTileFlags(pos) & ~TileFlags.LockColor);
    4. TMap.SetColor(pos, Pcolor);
    https://docs.unity3d.com/ScriptReference/Tilemaps.TileFlags.html
     
  3. LazyGhost15

    LazyGhost15

    Joined:
    Feb 12, 2022
    Posts:
    88
    I did that, but it didn't work either. After asking the color of each tile after coloring it I figured out all of the tiles are "White" (even tho I don't see any tiles).
    upload_2023-10-7_17-54-19.png