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. Dismiss Notice

Resolved Custom Rule Tile Not Updating Correctly

Discussion in '2D' started by bfisk121, Jul 6, 2023.

  1. bfisk121

    bfisk121

    Joined:
    Jan 24, 2020
    Posts:
    6
    I'm using a custom rule tile script for bridges. In my game, players are allowed to place bridges over water tile by tile. Although the bridge tiles and water tiles are not on the same tilemap, there is an invisible tile in the bridge tilemap for every water tile (I have made them slightly visible for the images in this post). This way, the bridge tile script senses if it is next to that invisible tile to know if it is next to water. Placing the bridge tiles works just fine according to all the rules.
    upload_2023-7-6_17-33-26.png

    Players are also able to remove the bridge tiles, and when this happens the invisible tile will be placed back since water is still underneath. When this happens, neighboring bridge tiles do not update properly:
    upload_2023-7-6_17-36-10.png

    However, upon removing another bridge tile adjacent to the one that didn't update correctly, it updates to the rule it should have previously been on. Note how the middle tile in the image below has the railing on the top of the tile (indicating water above that tile) but it doesn't have the railing in the previous picture. Also note the middle tile in the image below is missing legs so it is always one update behind.
    upload_2023-7-6_17-37-19.png

    Is this a bug or is there some way to get the tiles to refresh properly. Everything works fine when just manually placing and removing tiles in the editor. The one thing I can think of is when the bridge tile is removed, the tile at that square is first set to null and then back to the invisible tile all in the same frame, but why would it not update based on the most recent change?

    I'm on Unity 2021.3.15
     
  2. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    i assume that you are using settile once, and you arent using refreshtile on the adjacent tiles
     
  3. bfisk121

    bfisk121

    Joined:
    Jan 24, 2020
    Posts:
    6
    I haven't done anything with refreshtile - is that something I have to call manually in a situation like this?
     
  4. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    i would assume you need to call refresh tile on all neighbour tiles, otherwise they wont update to the new rule
     
  5. bfisk121

    bfisk121

    Joined:
    Jan 24, 2020
    Posts:
    6
    Thank you for your help, that worked. Although it's still a little puzzling why this would be an issue only when removing the tiles and not when placing them.
     
    karderos likes this.