Search Unity

Switch the prefab's Tile Palette

Discussion in '2D' started by JKH, Apr 2, 2021.

  1. JKH

    JKH

    Joined:
    Feb 19, 2013
    Posts:
    7
    Hi I'm making a 2d dot game.

    1.PNG

    As you can see in the picture, I have a map prefab and the tile palette.
    What I want to do is switch those map setting to another palette.
    How can I do that?? Please help me.
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    Hi, could you explain with more details on what you want to do? Having screenshots would help as well, thanks!
     
  3. JKH

    JKH

    Joined:
    Feb 19, 2013
    Posts:
    7
    For example, If we want to make a new game Map prefabs with same location tiles but using different tiles(Color, texture or something else), we have to create a new one and we think this is waste of time. So What I want to do is just change the tile palette and the game map prefab changes too!

    Is this possible work?
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @JKH

    "I want to do is just change the tile palette and the game map prefab changes too!"

    BTW - Tile Palette is a Tilemap with its Renderer disabled. You can test this by dragging your Tile Palette into your scene, it will look like this (Tilemap object is hidden in asset file, so it doesn't show up in Project view):

    upload_2021-4-14_18-0-0.png

    So it is a palette of tiles (created using Tiles on Tilemap). Tiles themselves are asset files in your project, and those asset files define how your tile looks. So, AFAIK - modifying a Tilemap (of Tile Palette) alone wouldn't change your scene Tilemap...
     
  5. JKH

    JKH

    Joined:
    Feb 19, 2013
    Posts:
    7
    Hi, Thank you for the explanation. I thought if there is any way to do it. Thank you very much anyway :)
     
  6. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @JKH

    I would simply have a folder of matching tile asset files and by pass the whole palette. I have no idea if there are some limitations with this method, but it worked for me. Using editor scripting, get the tiles of your tilemap, process each tile, replace it with a different version from another folder:

    20210415_tile_swapper.gif
     
    Last edited: Apr 15, 2021
    JKH and ChuanXin like this.
  7. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    eses likes this.
  8. JKH

    JKH

    Joined:
    Feb 19, 2013
    Posts:
    7
    Wow this is what I looking for. Could you please share it if it's possible???
     
  9. JKH

    JKH

    Joined:
    Feb 19, 2013
    Posts:
    7
    Hi, Thank you very much! this work really well LOL