Pixel Perfect Camera keeps moving and changing size? Bug?

I haven’t really used the Pixel Perfect camera component before, but it seems like it’s bugging out, unless this is intended behaviour. I am trying to learn the pixel perfect camera, to achieve the effect of:

On mobile, instead of having pillar / letter boxing, if the screen is a different size, then stretching the edges of the screen to fit. I assume that’s what the 2 squares are for - the dotted line being the critical main area, and the solid line being the extension? Unless I’m misunderstanding. In any case, my issue is below:

I have 2 monitors, which are different resolutions. One is HD, the other is 2560 x 1440. When the “Game” view window is on my larger screen, if I have the game window not maximized like the below screenshot, the green camera window looks like the above screenshot.

However, if I maximize the game window on my larger right screen, like this:

Then the main camera green square area looks like this:

The green square area gets smaller, throwing off where I placed all of my sprites. This seems like strange behaviour, which I assume is somehow related to the fact that my screens are both different resolutions.

For reference, the game view window is set to 16:9, which also gives an error:

Which doesn’t make sense to me on several levels:

  1. HD is also 16:9
  2. my games reference ration on the pixel perfect camera is 240 x 135, which is exactly 1/8 of HD

So either way you cut the cake, the pixels should be fine. The warning goes away if I set the camera aspect ratio to just HD. But if I do that, then I get this:

I don’t get the dotted lines anymore, and only a solid green line, which I am guessing will not expand out nicely like I want on different mobile screens and just stretch to fit. Maybe I am misunderstanding what this green camera outline is for and it doesn’t work how I think, and won’t do what I want, but either way, maximising or not maximising my game window seems like it should not affect anything.

I am honestly starting to feel like Unity Discussions is not working as well as the forum because I am having a lot less posts answered.

It might be 1/8th of 1080p, but it doesn’t divide evenly for 1440p, which is why it doesn’t look right.

When picking a reference resolution, you want to pick one that divides evenly across your expected targer resolutions.

This is why resolutions like 360p are popular as they divide evenly across all the major resolutions you’ll see.

1 Like

Thanks for your response, however, I’m a bit confused still. I don’t understand why having the “Game Window” being on one screen or the other affects the green square area, of my scene view, of the pixel perfect camera?

Because I set the reference target to “240 x 135” in the camera, so I would have assumed that’s what determines the size of the camera view and green square, not which screen the “Game Window” is on which, as far as I know, is purely for testing and didn’t expect it to affect the camera or game view? That’s what I’m finding most confusing.

I would have expected the only thing to affect the camera view, and green square area, to be the settings on the actual camera, which is locked at 240 x 135

Lets ignore the green boxes. It’s just distracting from how this stuff actually works.

The size of the camera is only one aspect of pixel perfect. The other aspect is actually how many pixels is being rendered in the target view. If you have a reference resolution of 240 x 135, but your game view is 1440p, then every pixel of your reference resolution equals 10.66 repeated pixels of your game view resolution, which obviously doesn’t work and will give you weird results.

You have your game view set to 16:9 free aspect, which means it will just use whatever resolution fills the view. This does not work with pixel perfect stuff, as you have to have a specific reference resolution that works with specific target resolutions.

Instead, use real target resolutions in your game view, and use a reference resolution that works across these target resolutions. And you also need a pixels per unit that fits evenly in said reference resolution as well.

I’m not sure where you got 240 x 135 from, but it will not work for 720p, 1080p or 1440p. It’s a terrible choice for your reference resolution. You should ideally pick one that divides evenly across all major resolutions, and a pixels per unit that fits nicely inside said resolution.

I picked 240 x 135, because I wanted to pick a smaller resolution in HD that divides evenly back into it. I’ve never heard of people making games at 360p before.

1080 / 135 = 8
1920 / 240 = 8

So it scales nice and crisp for 1080. However I hadn’t realised, you are correct, it does not divide nicely into 720 or 1440.
Doing some maths:

1080 / 3 = 360
1440 / 4 = 360
720 / 2 = 360

Honestly I hadn’t thought as much about those resolutions, I was focusing mainly on HD and 4k, but that makes sense.

I wasn’t actually noticing anything wrong with how the graphics appear, was mostly confused about the green camera window changing size and why it was giving me an error.

The reason I had it on 16:9 is because it gives you the 2 green squares - the outer, solid square, and inner dotted line. I had read that the inner dotted line was the “'critical area” and the outer was the “safe area”, and that when designing for mobile, this helps to stretch the screen for different screen sizes. Maybe I got the wrong information there.

You’re right, I was wrong about 1080p.

I think the borders are pretty much there to tell when there’s a mismatch between your reference resolution and your target resolution. In any case, it helps to understand how this works on a more fundamental level.

I would only be using free aspect resolutions for non-pixel art games. In the real world, your game is likely only ever going to be rendered at a set, standard resolution.

Based on steam hardware survey results, that is yes, primarily 1080p, but 1440p is also the second most common resolution nowadays, just shy of 20% of users: Steam Hardware & Software Survey

So you’d want your resolution of choice at least work for those two.

Well I might try changing it to 360p then, easy done at this point. Thanks. I am not having issues with the graphics displaying correctly normally, but I am getting weird issues on the render texture specifically. Not sure if that’s your area or not, made a separate post for that here: Pixels warping on render texture? Best way to set up render texture and second camera for water reflections?