Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I set the scale of a tile?

Discussion in '2D Experimental Preview' started by VinnieH01, Jul 31, 2016.

  1. VinnieH01

    VinnieH01

    Joined:
    Sep 3, 2014
    Posts:
    32
    How do I change the scale of my tile (Like you do when you change the scale of a Transform component)?

    Scale.png

    I cant find anything like this on my tile objects.
     
  2. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    Scaling is done with a Matrix4x4. You can set it with TileMap.SetTransformMatrix or TileData.transform.
     
    jahnkevin12 likes this.
  3. VinnieH01

    VinnieH01

    Joined:
    Sep 3, 2014
    Posts:
    32
    @Jay-Pavlina Where would I do this exactly, is there no way to do it in the inspector (Like scaling up a gameobject)?
     
    Deleted User likes this.
  4. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Are you trying to scale just one tile on the tilemap or your tile set to be scaled?
     
  5. VinnieH01

    VinnieH01

    Joined:
    Sep 3, 2014
    Posts:
    32
    I'm trying to scale every tile so that they fit into a 64 by 64 grid even though the graphics are 16 by 16 pixels (I still want the pixels per units at 1)
     
  6. Johaness_Reuben

    Johaness_Reuben

    Joined:
    Jan 27, 2016
    Posts:
    253
    Not sure if this is an ideal solution.
    Select the tile asset and set the transform values.
    Set Flags to Lock Transform
    upload_2016-8-4_0-44-23.png

    Currently the Tilemap Palette will not adjust to the size, so to select the tile click in the middle of the image.
    I'm curious as to why you're using these values. Could you share a little on what you're doing and why?
    Cheers
     
  7. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Can you give more insight why you insist on pixelPerUnit=1 and fitting 16x16pixel assets into 64x64 world unit grid?
     
  8. VinnieH01

    VinnieH01

    Joined:
    Sep 3, 2014
    Posts:
    32
    @keely @Johaness_Reuben First I set the cameras size to be the screen height / 2. I also offset the camera position by 0.1 in the x and 0.1 in the y. This removes all pixel streatching (http://i.imgur.com/cslZfEg.png). Then I set my pixels per unit on all my assets to 1 and then scale them to the approprite size using the transform options. This makes every unity unit one pixel on my screen. This gives me pixel pericise control of the positioning of my sprites (As long as I move using transform.Translate() or transform.position += ...). I also round the position of moving objects (also to remove pixel streatching). I created my own collision system using raycasts and kinematic ridgidbodys so I dont have to use the physics system. This setup is great for pixel art games since I can for example fine tune the speed of objects to remove jerkyness/choppyness and I overall have alot more control.
     
  9. VinnieH01

    VinnieH01

    Joined:
    Sep 3, 2014
    Posts:
    32
    @Johaness_Reuben Yeah, I agree its not and ideal solution (It works though I guess). If you belive its a good enough feature maybe you guys can create a easyer to use and better solutiuon to this. Something like "the normal transform scaling tools" and fix so that the pallet dosent totally mess up. Anyway thanks for all the help. :D
     
  10. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    I'm assuming you want x4 pixelart (one texel is four screen pixels).

    pixelsPerUnit=0.25 produces exactly the same rendering outcome than using 4x scaling matrix.

    Some differences in scripting:
    - Transform local space calculations differ (easy to match, though)
    - Transform scale affects children whereas pixelsPerUnit doesn't
    - Perhaps something else I'm missing?

    In any case, sounds like you are fond of your approach and don't want to change already working systems. Scaling per Tile asset like suggested is unfortunately your only option if you want to have grid size differ from your asset size.
     
  11. VinnieH01

    VinnieH01

    Joined:
    Sep 3, 2014
    Posts:
    32
    @keely @Johaness_Reuben I've got no problem scaling every tile asset. It seems to work pretty well, only problem is the pallet. If you can fix that, this would be a good solution. One thing I dont really understand is the flags on the tiles (Override Transform, override color, none etc). Can anyone explain?
     
  12. mstarr

    mstarr

    Joined:
    Jun 20, 2018
    Posts:
    135
    One solution is to make a tilemap, set the size of the tiles to automatic, then the first tile you drag and drop into the editor will determine the size of the tiles.
     
  13. AuroraSpirix

    AuroraSpirix

    Joined:
    May 12, 2020
    Posts:
    1
    I also have the same problem. When I drag in my 16px 16px image, it don't fix the box.
     

    Attached Files:

  14. Bushmansmeg

    Bushmansmeg

    Joined:
    Nov 11, 2020
    Posts:
    1
    exact same problem, can enyone help out?
     
  15. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,503
    1. Go to Tile Palette
    2. Select Cursor icon (shortcut = S)
    3. Ensure Tile Palette's target Tilemap is correct
    4. Select Tilemap with mouse in scene.
    5. Look at Inspector's Grid Selection info. If there's nothing there, you have the wrong target tilemap in Tile Palette.
    6. Change scale.

    Untitled - Copy.png

    You can also change it by script using tilemap.SetTransformMatrix(cell, newMatrix).

    HOWEVER, that said this problem:
    Actually looks like the image has the wrong pixels per unit (PPU). To fix that, go to the sprite's texture and adjust its PPU.
     
    Last edited: Nov 12, 2020
  16. mstarr

    mstarr

    Joined:
    Jun 20, 2018
    Posts:
    135
    I changed the PPU of my tile and it had no effect. Also, changing the scale of the tilemap does just that: changes the scale of the tile map, not of the tiles relative to the tilemap. So, no solution still? I'd think this would be like, super-basic.
     
  17. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,503
    This shouldn't be the case. Did you try much larger/smaller values? Just in case I'm not clear, I'm talking about Pixels Per Unit on the sprite's texture.

    You might also try by script:
    tilemap.SetTransformMatrix(cell, newMatrix)
    or you could create a custom tile that sets the tileData.transform automatically. It could expose a scale property for convenience.
     
    Last edited: Jul 25, 2021
  18. mstarr

    mstarr

    Joined:
    Jun 20, 2018
    Posts:
    135
    Change the cell size of the Grid. It will fix the problem. QED. :cool: