2
\$\begingroup\$

The Sprite import inspector has a Pixels Per Unit setting that controls the size of the sprite objects when they're added to the scene: enter image description here

Will Unity resize the sprite at run time or will it be resized after me changing the property and saved for the future?

\$\endgroup\$
5
\$\begingroup\$

First, a little clarification:

the Pixels per Unit setting controls the size of the geometry the image is rendered on. It does not rescale the raster image asset in memory or on the disc, like you might be used to when resizing an image in Photoshop or similar programs. Those operations can take some time, because the program needs to walk through every pixel in the new image and calculate its colour by sampling the corresponding pixels in its previous incarnation.

By contrast, the scaling that Pixels per Unit does is dirt cheap, operating on a handful of transformation matrices or vectors that the game was going to have to process anyway when sending them to the GPU to render each frame.

So, you shouldn't worry about the process of scaling itself causing a substantial performance impact.


Where pixels per unit can impact performance is in how the resulting size of your scene objects plays with Unity's acceleration structures for rendering and physics. Often these are tuned to assume that the stuff you're interacting with primarily - your player characters, trigger volumes, map tiles, etc - are on a scale between tenths to tens of units in size. If we think of a unit as a meter, then this lets us model interactions with anything from house pets to jumbo jets.

Keeping a pixels per unit setting tuned so that your gameplay happens in this size range lets these systems do their work smoothly. It can also help make your math easy as a developer, sticking to small numbers that are simple to work with and remember ("Map tiles are 1 unit, the player's dash move travels 3 units" etc).

You'll see an occasional tutorial though that says you should set your pixels per unit to 1, so that you can work in pixel coordinates for everything. I do not recommend this approach. Doing it this way, a single screen at 1080p spans 2000 game units, and most objects will be hundreds of units across. This can cause systems like physics to behave poorly because it's outside the range they've been tuned for.

So here again, the scaling itself isn't a significant performance sink, but the consequences it has on the size of your game interactions can be.

\$\endgroup\$
  • \$\begingroup\$ Oh! So much info! I am very grateful! \$\endgroup\$ – Yaroslav Jul 1 '17 at 21:21
  • \$\begingroup\$ Hm. Where is from did you get the info? I would like to get the same source. \$\endgroup\$ – Yaroslav Jul 1 '17 at 21:26
  • \$\begingroup\$ Can I consider the number in Pixels Per Unit property as the weight of one unit of my sprite when using Unity 2D Physics? \$\endgroup\$ – Yaroslav Jul 1 '17 at 21:29
  • \$\begingroup\$ I don't have a particular source to cite, it's just stuff I've absorbed over a few years of working in Unity. I'd welcome other answers with hard sources or corrections though. :) As for using the Pixels per Unit value as a physics weight, don't do that. Pixels per Unit is about the detail level of a particular raster asset. It doesn't tell you anything about how big or weighty the item it represents is. I could have a 300 PPU feather pillow next to a 100 PPU anvil, both rendered the same size on-screen. You may even want to swap between different PPU assets depending on the screen resolution. \$\endgroup\$ – DMGregory Jul 1 '17 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.