[SOLVED] Weird positioning of tiles in tile pallette

Not really sure how to explain this one without using images. Basically, I’m taking a 512512 image, splitting it into 256 tiles of size 32 and putting it into a tile palette. I expect to get a 1616 setup in the palette, but instead I get a 1716 tile setup in the palette, where line n has an offset of n tiles from the setup I want. Surely there is no logical reason for it to pick 1716 instead of 16*16?

See picture 1 for original tileset and picture 2 for result in tile palette. In this case I didn’t even get the same offset, so there appears to be some kind of random element to it as well?

I can’t be the only one with these problems?

  • Are there any known plans to fix this in the close future?
  • Am I simply doing something wrong?
  • Can I somehow script my way around this? I can’t find any methods to interact with the palette.

I know I can edit the palette manually, but it’s a ridiculous workflow, especially for larger tilesets, and with lack of undo functionality in the palette.

I have no idea what to do here, please help :slight_smile:

Sorry to bump my own question but I just googled the question again and this is the top result… Does anyone have a good solution?

EDIT:
I put the below in an editor script which can be used on any tilesets being put into tile palettes.

Note that the variable “setWidth” is the width of the tileset. Will probably optimize this process for myself a bit more, but for now this can fix the problem for anyone, just change the variable to the width of your tileset. To use, just click on a palette in the inspector and use the menu item.

This code assumes that your tilebase objects have numbered names from their order in the original tileset on the format of name_n. For example “sewer_1”, “sewer_2” … “sewer_n”

[MenuItem("Custom Tiles/Fix Palette")]
    static void FixPalette()
    {





        GameObject[] selection = Selection.GetFiltered<GameObject>(SelectionMode.DeepAssets);

        Debug.Log(selection[0].transform.childCount);


        GameObject gameObject = selection[0];

        Tilemap tilemap = gameObject.GetComponentInChildren<Tilemap>();
   

        TileBase[] allTilesUnFiltered =
            tilemap.GetTilesBlock(tilemap.cellBounds);

        List<TileBase> allTiles = new List<TileBase>();
     

        foreach( TileBase tile in allTilesUnFiltered )
        {
            if( tile != default(TileBase) )
            {
                allTiles.Add(tile);
            }
        }

        allTiles.Sort( (TileBase a, TileBase b) =>
        {

            int numA = Int32.Parse(a.name.Split('_')[1]),
                numB = Int32.Parse(b.name.Split('_')[1]);


            return numA - numB;

        });

         
        int setWidth = 12;

     
        int w = setWidth, h = Mathf.CeilToInt(allTiles.Count / setWidth);
        TileBase[,] arrangedTiles = new TileBase[w,h];



        for (int i = 0; i < allTiles.Count; i++ )
        {
         
            int x = i % w;
            int y = Mathf.FloorToInt(i/w);
            arrangedTiles[x,y] = allTiles[i];
        }

        tilemap.ClearAllTiles();

        for (int x = 0; x < w; x++ )
        {
            for (int y = 0; y < h; y++ )
            {

                tilemap.SetTile(new Vector3Int(x, h-y, 0), arrangedTiles[x,y]);

            }
        }



    }

Okay so this may be a really late reply but I think I remember solving this awhile back by dragging the spritesheet source image into the tile pallete, instead of selecting all the tiles. Good luck whoever reads this :smile:

4 Likes

At the moment it seems to be bugged. Because when dragging in some textures the positioning is fine, while with other textures it is as you have showed above. I’m trying to figure out why, but haven’t yet. I did find some workarounds.

Thing’s I’ve found:

  • the size of the texture doesn’t seem to make any difference, some big some small are screwed

  • clearing the cache doesn’t do anything

  • creating a palette in a new project with the same texture, does work, so somehow some information in my current project is screwing it up

  • Richt-clicking and doing a “reimport” doesn’t work

  • copying the texture and forcing a reimport like that DOES fix the problem :smile:

  • Opening the sprite editor and slicing the texture again does fix the problem (but of course you might loose a bunch of work that way)

I suspect the broken textures might have originally been imported in a broken version of Unity, I’m unsure when I first imported them, but only now started using them.
Hope this helps someone maybe :slight_smile:

I had this doing a tutorial. The spritesheet has gaps between the tiles, like so:

6032777--651254--upload_2020-6-28_10-53-17.png

The sprite editor can slice it no problem, but the palette reads in the wrong number of rows columns and makes this when the sprite (as a whole, dragging only the top-level item from the project) is dragged in:

6032777--651257--upload_2020-6-28_10-54-57.png

Dragging in the individual sprites produces a more compact set, but, again, with the wrong number of rows and columns:

6032777--651260--upload_2020-6-28_10-55-38.png

The workaround that worked for me was editing the original spritesheet .png file to get rid of the empty spaces between tiles. I haven’t tested vvey’s script, but it sounds like the right solution in theory. None of The-Oddler’s fixes worked for me.

Just thought I’d throw this out there for internet searchers since it’s over a year later and still an issue.

Here’s another thread on the issue, looks like this has been a sporadic problem since 2016: [Feature request] Palette tiles ordered like in tileset sprite

Hi, we will check this out. Just to confirm, does this still happen in 2019.4? Thanks!

1 Like

Yes, I’m using the most recent 2019.4 version.

It looks like this has been fixed in 2020.1. We will see if we can bring this back to 2019.4!

1 Like

thanks!!

Hi. I had this problem in Unity 2019.4 so I updated to Unity 2020.1 but I still have the same bug/issue. Is there a specific way to fix this?

6465418--725260--Capture.PNG

For your texture, could you share the sizes of your sliced Sprites in the Texture? The ordering will not work if the sizes are not uniform.

oi, estou usando a versão 2020.3 e o problema ainda existe, estou cortando ladrilhos automaticamente no editor de spriter (os ladrilhos a serem cortados são múltiplos e apontam (sem filtro)

7135622--853061--Screenshot 2021-05-12 204258.png

cada vez que cierro la aplicacion de unity, se me desaparese el title palette, y no me deja poner otro