Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Invalid Matrix and Garbage Color in Tile Palette when saving

Discussion in '2D' started by Strikerklm96, Jun 10, 2019.

  1. Strikerklm96

    Strikerklm96

    Joined:
    Apr 7, 2016
    Posts:
    2
    In the Tile Palette, when hitting Ctrl+S to save my work, some of the tiles get an Invalid Matrix and set their Color values to float4(191,191,191,0) for no apparent reason. This causes the tile to disappear until it is fixed.

    Even just adding a tile to the Tile Palette somehow causes the values to be fixed, until it happens again.
    So far I have experienced this consistently and in two different Unity versions, so I assume there is something wrong with my project/code.

    broken_unity.PNG

    Code (CSharp):
    1.     public class Tile : TileBase
    2.     {
    3.         public virtual Sprite PreviewSprite { get; protected set; }
    4.  
    5.         public LayerType LayerType;
    6.         public TileType TileType;
    7.         public GameObject Object;
    8.  
    9.         public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
    10.         {
    11.             tileData.sprite = Object.GetComponent<SpriteRenderer>().sprite;
    12.             tileData.color = Color.red;
    13.             tileData.flags = TileFlags.None;
    14.             var m = tileData.transform;
    15.             m.SetTRS(Vector3.zero, GetRotation(), Vector3.one);
    16.             tileData.transform = m;
    17.         }
    18.  
    19.         private Quaternion GetRotation()
    20.         {
    21.             return Quaternion.Euler(0f, 0f, 0f);
    22.         }
    23.  
    24.         [MenuItem("Assets/Create/Tiles/Simple Tile", false, 0)]
    25.         public static void CreateSimpleTile()
    26.         {
    27.             TileBuilder.CreateTile<Tile>(LayerType.None, "SimpleTile");
    28.         }
    29.     }
     
  2. Strikerklm96

    Strikerklm96

    Joined:
    Apr 7, 2016
    Posts:
    2
    I believe the issue had to do with referencing dead assets or assigning the tileData.sprite to Object.GetComponent<SpriteRenderer>().sprite was causing the issue.