Pixel Perfect Camera and Multiple Resolutions

Hello !
I having an issue with my pixel art game, when I try to change the resolution of the game it only zooms the game in or out, not re-scaling the graphics as it is supposed to be … so basically the game is working fine on 1920x1080 … if i switch to 1280x720 the graphics zooms out and black bars appears on both sides of the screen, its making me crazy … trying to resolve this for the past 18 hours non-stop!

Pixel Perfect Settings

Resolution 1920x1080:

Resolution 1280x720:

Ummm, using 640x480 as reference was causing the issue … it’s basically 4:3 aspect ratio where I am showing the final result on 16:9 aspect ratio (1920x1080 or 1280x768).

I will try to run some tests in different 16:9 aspect ratio …

Why would it rescale your sprites? It’s not “supposed” to rescale pixel art, that’s not how images work in the first place… If you have a 32x32px sprite, how are you supposed to make it 50x50px large?

We can continue this problem on to your aspect ratio: If you have a 32x32xp sprite in a 4:3 aspect ratio, what is gonna happen if you change the aspect ratio to 16:9?? Suddenly you have an image that’s not a square, stretched on either the width or height. How is any algorithm gonna stretch it? Of course not! The pixel perfect camera adds the black bars so the camera aspect ratio stays the same.

Also, please NEVER change the scale away from 1 in the display settings… This is only a zoom feature for the rendered image, you should change the zoom of the camera component instead.

It looks like I didn’t explain it well, nor I will find the right words for it … but i will give it a try:
changing the resolution … “was” changing the game play … which requires to includes or excludes extra assets / monsters to cover the extra sides, as the aspect ratio changes.

I don’t depend on the scale of the display, i export the game and try it …yet it was just to show you the most left side of the screen.

Thanks for your suggestion and tips.

So its more a problem of game logic and less of something not resizing correctly?
Maybe you’ll have to code the camera logic yourself then… So you can input your checks to spawn additional prefabs…

Looking at the Unity docs though
https://docs.unity3d.com/Packages/com.unity.2d.pixel-perfect@1.0/manual/index.html

You shouldn’t be getting black bars if Crop Frame isn’t set.
Maybe try it without the upscale render texture? Since that always creates a render texture at your specified resolution, so upscaling to a different aspect ratio might be impossible?

Thanks for your swift reply…
about the black bars … they aren’t a crop bars , they are actually the end of the assets (the end of the background) so no more asset the background color (black) appears, I tried with and without upscale texture, I was able to figure it out as i said previously by making sure all resolution following 1 aspect ratio, so no more black bars OR end of assets.

However; if i change resolution on full screen (after exporting) i dont feel the change, if i make it windowed mode then yes i can see the window is getting resized … changing the resolution should actually change it not just resizing the game window in windowed mode, it should effect the full screen mode as well, am I right ?

How do you change the resolution at runtime in a build?

public void setScreenRes(int W, int H)
{
Screen.SetResolution(W, H, FullScreenMode.ExclusiveFullScreen, 60);
}

and you can call it like this:
setScreenRes(1920, 1080);

So at this point, your real problem is that Screen.SetResolution in a build behaves differently than changing the window size inside of the editor and changing the window size in a build? Does changing the window size in a build do the same as changing the window size in the editor?

Sadly, I’ve never used SetResolution in a build so I can’t really help you with this specific problem it seems.

1 Like

Well thanks a lot @Xiromtz at least you are the only one who tried ! :stuck_out_tongue: I reached to my desired result but having different cameras each with its own pixel perfect component, I enable and disable them according to the selected resolution, i can now have pixel perfect in multiple resolution and showing the same view for both of them (Full HD and 4K).

1 Like

I had been looking for a solution to this problem with the same constraints for a long time and this approach seems to be the one I was looking for. Thanks :smile:

Sweet!