0
\$\begingroup\$

I'm having trouble figuring out how to change the scale (size) of a single sprite (tile) on a Unity Tilemap.

In the game, I place trees as tiles on a tilemap, and when they grow over time, I want to increase the scale of those trees on specific tile. (different trees can be in different growth states)

Every option I tried or looked up so far only seems to work for rescaling the entire tilemap, not only a single, specific sprite (tile) on the tilemap.

Is there any way to achieve this functionality?

EDIT: I notice the Tile class documentation mentions a transform property which is a Matrix4x4. I'm not sure if this can be used to change the size or how.

\$\endgroup\$
1
\$\begingroup\$

After further research, I figured it out.

If you wanted to increase the size of a specific tile by two times, all you need to do is unlock the tile flags and set the new scale matrix like so:

Matrix4x4 newMatrix = Matrix4x4.Scale(new Vector3(2, 2, 2));

Tilemap.SetTileFlags(position, TileFlags.None);
Tilemap.SetTransformMatrix(position, newMatrix);

There is also Tilemap.SetColor and works in a similar way.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ You don't need to multiply your scale matrix by the identity matrix. Multiplying by the identity matrix, by definition, does not change anything — that's what "identity" means in this context. \$\endgroup\$
    – DMGregory
    Jan 8 at 10:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .