- Home /
SetTile vs SetTiles
What is faster? Looping through each tile and use SetTile, or looping through each tile, add it to a list/array, then use SetTiles?
Tilemap tilemap;
foreach (var pos in tilemap.cellBounds.allPositionsWithin)
{
if (/* some condition */)
tilemap.SetTile(pos, /* Your tile here */);
}
Or
Tilemap tilemap;
List<Vector3Int> allPositions = new List<Vector3Int>(tilemap.cellBounds.size.x * tilemap.cellBounds.size.y);
foreach (var pos in tilemap.cellBounds.allPositionsWithin)
{
if (/* some condition */)
allPositions.Add(pos);
}
tilemap.SetTiles(allPositions, /* Your tile */);
Comment
Answer by Vivien_Lynn · Aug 23, 2021 at 11:55 AM
I would assume that there is no real difference between the two.
If you really want to know, you can use the Stopwatch class to analyze this yourself.
Testing it yourself is always a good idea, because you can analyze this for you specific case. For example it could be that one is faster then the other for small amounts of data, but becomes slower when using bigger amounts of data, because of potential overhead.