Search Unity

Tilemap SetTilesBlock Performance

Discussion in '2D' started by JasonBricco, Jun 22, 2018.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I have a question for the Unity developers that I'd love an answer to.

    How come it takes over 20 minutes to set 786,000 tiles to a tilemap via SetTilesBlock()?

    All I'm doing is:

    Code (CSharp):
    1.  
    2. int index = 0;
    3. for (int x = 0; x < Size; x++)
    4. {
    5.     for (int y = 0; y < Size; y++)
    6.     {
    7.         for (int z = 0; z < Layers; z++)
    8.         {
    9.             Entity entity = EntityType.Grass;
    10.             sprites[index++] = entity.Sprite();
    11.         }
    12.     }
    13. }
    14.  
    15. BoundsInt bounds = new BoundsInt(0, 0, 0, Size, Size, Layers);
    16. tileMap.SetTilesBlock(bounds, sprites);
    where Size = 512, Layers = 3, and sprites references a list of EntitySprite, which derives from Unity's Tile class.
    So I'm setting a class instance that inherits from Tile into a 512x512x3 area.

    It's been over 20 minutes and it still hasn't finished.

    I don't know how it's even possible to make something this slow...

    This is on Unity 2018.1.5.

    (And yes the triple for loop is pointless in this example, but that's a simplified version of what the code should be.)
     
    Last edited: Jun 22, 2018
    ph3rin and DaseinPhaos like this.