Unity-Technologies / 2d-extras

Fun 2D Stuff that we'd like to share!
Other
1.54k stars 342 forks source link

RuleTile graphical rendering bug with SetTilesBlock() in Unity 2021+ #324

Open aroman opened 2 years ago

aroman commented 2 years ago

Hi,

There seems to be a rendering bug with 2d-extras, such that depending on the API used to programmatically set TileMap data from a script, the RuleTiles may appear "invisible".

In short, this code results in the tiles which are visible:

for (var x = 0; x < 10; x++)
{
    for (var y = 0; y < 10; y++)
    {
        var position = new Vector3Int(x, y, 0);
        someTileMap.SetTile(position, someTile);
    }
}

This code, however, does not:

var area = new BoundsInt(Vector3Int.zero, new Vector3Int(10, 10, 1));
var tileArray = new TileBase[area.size.x * area.size.y * area.size.z];
for (var i = 0; i < tileArray.Length; i++)
{
    tileArray[i] = someTile;
}
someTileMap.SetTilesBlock(area, tileArray);

Now, what's very strange is that both snippets work correctly if someTile is a regular Tile, rather than a RuleTile. )In practice, the type of someTile is TileBase, and I provide it from the inspector.)

To be clear: in BOTH cases, the Tile data is being set in the TileMap. In fact, this can be confirmed graphically with the palette editor, which will change the brush preview correctly based on the underlying Tilemap data (see 1:48 in the video demonstration I linked below). The issue is, those tiles do not appear in either the game view, scene view, or built projects.

I made a brief video to demonstrate the bug: https://www.youtube.com/watch?v=uarGP83B5hQ

aroman commented 2 years ago

As an update, I've confirmed that this issue is only present in Unity 2021 and 2022, but NOT on 2020. Latest versions of all of those release trains.

ChuanXin-Unity commented 2 years ago

Thanks! I posted an update on this issue at https://forum.unity.com/threads/2021-2-0f1-tilemap-settiles-not-working-as-previous.1190572/#post-7682245, and hopefully will be able to confirm a fixed version for 2021.2 soon.