Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

RuleTiles in procedural worlds

Discussion in '2D' started by Imakhiil, Oct 31, 2019.

  1. Imakhiil

    Imakhiil

    Joined:
    Oct 11, 2013
    Posts:
    96
    Id like to generate a map on runtime (Using Tilemap.SetTile). Setting standard tiles works just fine but if I try to use RuleTiles from the 2d extras package nothing happens even though types match.
    Is this potentially a bug?
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,799
  3. blu3drag0n

    blu3drag0n

    Joined:
    Nov 9, 2018
    Posts:
    94
    Hi,
    it's not used to be a bug, you have to customize the refreshing manually as well.

    Have you tried
    Code (CSharp):
    1. map.RefreshAllTiles();
    at the end of your drawing ?

    If thats not working, you need to nest loops around the currently painted tiles position, to refresh their neighbours, like
    Code (CSharp):
    1.  
    2. int currentDrawPostionX = 5;
    3. int currentDrawPostionY = 8;
    4. Vector3Int drawPostion = new Vector3Int(currentDrawPostionX, currentDrawPostionY, 0);
    5. map.SetTile(drawPostion, currentTileToPaint);
    6. Vector3Int refreshPosition = new Vector3Int(0, 0, 0);
    7. for (int xAxis = currentDrawPostionX - 1; xAxis < currentDrawPostionX + 1; xAxis++)
    8. {
    9.     for (int yAxis = currentDrawPostionY - 1; yAxis < currentDrawPostionY + 1; yAxis++)
    10.     {
    11.         refreshPosition.Set(xAxis, yAxis, 0);
    12.         map.RefreshTile(refreshPosition);
    13.     }
    14. }
    15.  
    KR
    blu3
     
  4. aybarsmete1

    aybarsmete1

    Joined:
    Oct 26, 2019
    Posts:
    43
    Hey, can you share your procedural tilemap generation code with me? Thanks.