Revisiting Tiled2Unity Scale with Scaled Vertices

by Seanba on March 1, 2015

Scaled Vertices

A while back I offered a solution for Tiled2Unity users that wanted to partner scaled sprites (using a Pixels Per Unit value that was often the 100:1 default) with exported maps that used the (totally more sane) metric of one pixel per one unit in Unity.

Turns out that solution sucked. (more below)

Now, starting with Tiled2Unity 0.9.8.1, the desired scaling can be baked into the vertices that make up your meshes and collision geometry.

You can set the vertex scale in the Tiled2Unity UI:

Scaled Vertices in Tiled2Unity UI

Or you can use a command line argument (-s=VALUE or --scale=VALUE).

  • From Tiled: Tiled2Unity.exe %mapfile -s=0.01 c:\My\Unity\Project\Folder
  • From command line: Tiled2Unity.exe c:\My\Map\Folder\MyMap.tmx --scale=0.01

Both examples scale your vertices down to 1/100th of a unit which will be the most common. You can use other values though.

Problem With the Original Solution

The old way of scaling your exported maps was to instruct Tiled2Unity to hardwire the Transform component of the created prefab so that its scale matched the unity:scale map property in your TMX files. This became be a problem should GameObjects transfer in and out of your object hierarchy which is a common enough thing someone may want to do.

Not to beat a dead horse (and I say this as someone with a ton of enthusiasm for Unity) but I view the Pixels Per Unit setting in Unity to be a huge hack just to get sprites working with Box2D Physics which is a bad idea anyway for retro 2D games. I just don’t use it. However, if that’s the way you roll I now encourage you to use vertex scaling to get the job done.

If you decide to go this route keep in mind that the unity:scale property is still honored so make sure to rip it out of your TMX files. Otherwise, you’ll end up with prefabs that are scaled twice over.

Happy developing.

Update: User Adam offers an alternative way to think of scale in relation to physics …

For games that do use the physics engine, it seems to me that setting the pixels per unit to the size of your tiles makes sense, in my case 16. That’s because as far as the physics engine is concerned, one unit is one meter. With a tile size of 16, 100 gives you colliders that are too small and 1 gets into some large values that make me worry about floating point errors.

I can’t argue that. For people relying on the built-in 2D physics provided by Unity this sounds like a reasonable approach.

By the way: If you enjoy using Tiled then please consider contributing to Thorbjorn Lindeijer’s Patreon so that he can work on Tiled fulltime. It’s a great deal for our development community. Even a buck or two per month helps.

{ 3 comments… read them below or add one }

Adam March 5, 2015 at 7:43 pm

Hi Sean, thank you so much for this update! And for this wonderful tool in general.

For games that do use the physics engine, it seems to me that setting the pixels per unit to the size of your tiles makes sense, in my case 16. That’s because as far as the physics engine is concerned, one unit is one meter. With a tile size of 16, 100 gives you colliders that are too small and 1 gets into some large values that make me worry about floating point errors. Anyway, that’s just my two cents- this update makes it easy to use whatever value you want!

Kyle Nunery April 9, 2015 at 1:44 pm

+1 to Adam’s comment. Definitely set the pixels per unit to your tile size. I would like to learn more about why you recommend dropping the 2d physics engine for retro games.

Mark September 7, 2016 at 11:36 am

The label next to Vertex Scale on the latest version is even more confusing than it used to be.

Why would I set this to the inverse of unity’s Pixels Per Unit?

Inverst of +100 is -100?? Does that make sense?

It also contradicts the advise on this page which says set it to the tile size. Which worked brilliantly for me on my 32 and 64 pixel tiles.

Seanba sez: Hi Mark. The inverse of 100 is 1/100. So, if you wanted 1 pixel to represent 100 units then the vertices would be scaeld by 0.01. However, months ago I changed this feature to simply be “Pixels Per Unit” (the same as in Unity for sprites) and the tool does the vertex scaling math behind the scenes. Too many people were trying exotic “Pixels Per Unit” settings like 16 and 32 in Unity, thinking the inverse was 16/100 and 32/100 instead of 1/16 and 1/32.

But long story short: It sounds like you’re on a old version of Tiled2Unity. Update it and just set “Pixels Per Unit” like you normally would in the Texture Importer settings for your sprites.

Leave a Comment

Previous post:

Next post: