Search Unity

Bug Animated Tile Bug

Discussion in '2D' started by rarac, Mar 29, 2021.

  1. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    I was wondering if anyone encountered a similar bug with animated tiles

    I set a row of animated tiles on the leftmost edge of my tile map. Whenever I use settile somewhere else on the map all the animated tiles on the leftmost edge of the tilemap all shift graphic for a split second before returning to the correct graphic.

    This seems to be related to the way I am creating the animated tiles, I have every frame on a texture sheet, and whenever I write to that sheet and apply the previously layed animation tiles spaz out and display a different sprite randomly chosed from within my texture sheet.

    This strikes me as odd since I am not calling for refresh on those tiles and it only happens to the tiles that are on the left edge of the tilemap, also it only happens for 0.2 secs then it comes back to normal.

    2019.4f version

    I have been trying to narrow down the problem further and submit a reproductible bug report but my project is in an advanced state and Ive been having an hard time to isolate the cause of the problem
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    If you can reproduce the issue, that would be great!

    Would it be possible to share how you are creating the Animated Tiles? Possibly we could deduce the issue from this, thanks!
     
  3. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    Thanks for the reply I nailed down the issue. This is a very specific situation here's what happens:

    1 - I use set tile to lay down a chunk of tiles

    Code (CSharp):
    1. for (int x = -1; x <32;x++){
    2.  
    3. for (int y = -1; y <18;y++){
    4.  
    5. vector3int pos = new vector3int ( x, y, y);
    6. mastertile.sprite = spritearray[x + y*18];
    7. tilemap.settile(pos,mastertile);
    8.  
    9. }
    10. }
    2 - I then place some animated tiles on the edge of the tilemap, for example on position (-1,3,3) and others in the middle (15,8,8) for example

    3 - If i call set tile to replace any of the non animated tiles on the tilemap
    Code (CSharp):
    1.  
    2. vector3int pos = new vector3int ( 5, 9, 9);
    3. mastertile.sprite = spritearray[5+ 9*18];
    4. tilemap.settile(pos,mastertile);//Bug happens here
    5.  
    this will cause the animated tiles with x=-1 to glitch out for 0.2 seconds and replace themselves with a random tile that exists on the tilemap, before returning to the correct animation. ( note that this only happens to the animated tiles on x=-1, the others are fine)

    this is the bug

    4 - how I worked around it

    I created an empty animated tile and if I set it on the tilemap in the position (-2,3,3) and on the same frame I set my normal tile the bug does not happen, so I have something that looks like this:

    Code (CSharp):
    1.  
    2. vector3int pos = new vector3int ( -2, 3, 3);
    3. tilemap.settile(pos,null);
    4. tilemap.settile(pos,blankAnimatedTile);
    5.  
    6. vector3int pos = new vector3int ( 5, 9, 9);
    7. mastertile.sprite = spritearray[5+ 9*18];
    8. tilemap.settile(pos,mastertile);//Bug no longer happens
    9.  
    There is more to this fix in my situation but it doesnt matter for this explanation, I have only to note that in this case I am using only 1 tile for my inert tiles and just changing the sprite before setting it, and 1 animated tile that I change the array of sprites before setting it, so my tilemap only contains 2 tiles, so as I draw tiles on the tilemap mesh I never refresh the whole tilemap otherwise every tile would change back to the current sprite on the main tile.

    This is a wonky issue I hope this helps ( Also this only happens if you are using chunkmode = individual )
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Thanks! We will check this out!