Using Pixels Per Unit VS Scaling the object?

So here, he’s using this field to resize the ball:

I instinctively used the object scale first. AFAIK he never addressed why use one or the other, so I searched in this forum first and came with this explanation:

However, number 1 seems to be a contradiction. If it helps to have universal pixel density, then one should leave the PPU’s to the same value instead of using on each one to resize it, right?

I understand the other two but still isn’t clear to me why use one method vs the other.

The reasons Gerald_Burke mentioned are quite valid, so I’ll just add to that:

I heard on an official Unity tutorial, which I took years ago, that scaling an object makes the GPU work harder because it has to recalculate the pixels and shape based on the transform values, but if you change the PPU it won’t do that because that’ll be the default value, that means less work for the GPU.

Also, setting the PPU value allows you to have far more control over the object, it might not be that obvious at first, but let’s say that for some reason you have to child an object that has a scale other than (1, 1, 1), and the parent needs a different scale too, that makes everything extraordinarily obnoxious to work with, especially if you start rotating the objects, so it’s better if you simply adjust the PPU instead of doing some crazy math to approximately have the size you desire.

2 Likes

Thank you, I’ll use PPU. However, point one still seems contradictory and I’m trying to reconcile it in my head. He said:

  1. Having a universal pixel per unit can help you to have a universal pixel density. With pixel art, objects can look out of place if the ‘pixels’ that make them up are much larger or smaller than the ‘pixels’ that make up the world or objects around them.

Doesn’t a “universal PPU” mean having the same number for the PPU in all my objects? For example, 100 PPU.

EDIT:
I was just now resizing the items changing their PPU. The ball and the brick have 250 and 100 PPU respectively. And they are both 1,1,1 in scale. However, the brick is at least 3 times the size of the ball, so shouldn’t I make its scale 3 times that of the ball? 3,3,1 for example? Otherwise I’m saying the ball and the brick are both one unit in size which… they are visibly not. I may be overthinking this, but I thought I’d ask.

Hi,

Usually, if you create your own sprites, you make their dimensions relative to one another. The sprite for the human would, for example, be 100 x 100 px but the house would be 400 x 400, or something like that. In this scenario, a “universal PPU”, e.g. 100, would make sense because we want the house to be bigger than the human in the scene. The human could be 1 World Unit high (WU), the house 4 WU. Unity does that automatically for us.

However, if we set the PPU of the human to 100, and the PPU of the house to 400, both sprites would fill out 1 x 1 WU, which is probably not the desired ourcome.

I don’t know if the scale values have got a significant impact on the performance of the shader. Theoretically, the shader has to “work” anyway because 1 WU does not necessarily match a 100 x 100 px square on our monitor.

Changing the scale is “dangerous” if you want to use the game object in the physics simulation. The mass of the game object could be affected by the scale. For this reason, it’s “better” to use the PPU for increasing/decreasing the size of a sprite in your game.

Hope that makes sense. :slight_smile:


See also:

2 Likes

When I’m producing my own sprites it makes total sense. Using someone else’s (like the ball and the paddle), shouldn’t I aim to make the world units making sense?

By that I mean trying to modify the PPU first and second scale it in a way that an object four times the visual size of another to be 4 times its size in WUs?

If all sprites are supposed to have the same size in your game, it’s fairly convenient to simply do it via the PPU parameter. For example, if you have two characters who are both supposed to be 1 x 1 WU in the scene, but one has got a resolution of 123 x 123 px and the other one of 25 x 25 px, you would set the PPU to 123 for the former, and to 25 for the latter. Done.

Why would you want to use the scale for that?

Assuming you had a 25 x 25 px sprite, and its PPU is currently set to 25. This would make Unity render the sprite on 1 x 1 WU. If you wanted to increase the size fourfold, all you had to do is to divide the PPU value by 4.

25 / 4 = 6.25.

6.25 would be the new PPU value for the sprite.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms