Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Canvas with Pixel Perfect Camera

Discussion in '2D' started by Quecken, Oct 28, 2019.

  1. Quecken

    Quecken

    Joined:
    Feb 5, 2019
    Posts:
    8
    Hi!

    I'm making a game using the Pixel Perfect Camera component, but having issues making text in the UI scale properly for different resolutions. It just ends up blurry or distorted.

    Here are the PPC component settings I'm using:
    upload_2019-10-28_22-7-24.png

    I'm using a canvas for the UI, with an image containing a couple of text elements and a button. Here are my canvas settings:
    upload_2019-10-28_22-8-56.png

    Here's how the text looks in my scene view:
    upload_2019-10-28_22-11-15.png

    I'm using this font (TTF version), with size 16 for "Name" and 8 for the other texts: https://assetstore.unity.com/packages/2d/fonts/free-pixel-font-thaleah-140059.

    As you can see in the image above, the text is very blurry, and this is how it looks in my game view, with a resolution set to 320x180 (same as PPC component):
    upload_2019-10-28_22-12-49.png

    I would like the text to be pixel perfect without any blurring or distortion no matter the resolution (if that's even possible). As of now I can't get the font to render nicely at all in any view. Not even when trying to run a build of the game. Any help is greatly appreciated. If you want me to provide some more information I'd be happy to. Thanks!
     

    Attached Files:

  2. Sam_Ooi

    Sam_Ooi

    Unity Technologies

    Joined:
    Mar 5, 2018
    Posts:
    61
    Hi Quecken, Screen Space - Overlay mode is not supported by the Pixel Perfect Camera, but the other two Render Modes should work. Could you try setting your Canvas Render Mode to either Screen Space - Camera or World Space and see if the font scales cleanly?
     
    Quecken likes this.
  3. Quecken

    Quecken

    Joined:
    Feb 5, 2019
    Posts:
    8
    Hi Sam_Ooi. Thank you for taking the time to help me out. I changed the Render Mode of the canvas to Screen Space - Camera, and attached my camera containing the pixel perfect component. I also changed the Canvas Scaler to use Scale with Screen Size, which seems to have the desired effect. These are my current settings:
    upload_2019-10-29_8-8-24.png

    The UI text scales nicely now and doesn't get distortet or blurry. However, now I can't get the UI to adapt to the screen size. I thought setting the Screen Match Mode to Shrink would make the canvas adapt to the screen size, but the UI elements get pushed out of the view when the window changes size.

    Here's an image of a build using the above settings:
    upload_2019-10-29_8-26-44.png

    And this is how I've set up my Game view now:
    upload_2019-10-29_8-27-40.png
     
  4. Sam_Ooi

    Sam_Ooi

    Unity Technologies

    Joined:
    Mar 5, 2018
    Posts:
    61
    I see, okay here is a sample scene with a custom UI scaling script that may help. Could you let me know if replacing the Canvas Scaler with the Custom one helps the UI to scale properly?
     
  5. Quecken

    Quecken

    Joined:
    Feb 5, 2019
    Posts:
    8
    Aha! Thank you so much! Using the custom Canvas Scaler script seems to do the trick. The UI scales nicely with the screen size, and the text looks good. Just out of curiosity, I looked into the script and tried to understand exactly what it does, and I think I get most of it. There are some nice comments in there. But if you have time I'd love a short explanation of how it's implemented and what it does differently from the default scaler. And will this custom scaler be part of some future "pixel perfect package"?

    I have one last question regarding scaling and resolution. When building, I'm using the following settings:
    upload_2019-10-29_10-14-58.png

    If I change the Fullscreen Mode or the Width/Height, the changes don't seem to apply unless I do some other change in the player settings. Such as change the company name, version or something else. Is this a known issue?
     

    Attached Files:

  6. Sam_Ooi

    Sam_Ooi

    Unity Technologies

    Joined:
    Mar 5, 2018
    Posts:
    61
    Quoting from the dev: "So the reason of UI being cut is the Canvas Scaler doesn't take viewport into account when doing canvas scaling, while the Pixel Perfect Camera will modify the VP to crop the frame... I also talked to the UI team to let them consider making this viewport-aware scaler a built-in functionality."

    I'm unsure if the UI team has considered the function he's suggested, but I can check with the dev if the custom scaler would be included in future versions of the Pixel Perfect Camera.

    That's strange, the best would be to submit a bug report about this and include the project file.
     
  7. Quecken

    Quecken

    Joined:
    Feb 5, 2019
    Posts:
    8
    Ah alright, I see. That makes sense. I'll dig into the code a bit more as well. I'll submit a bug report about my player settings issue. Thank you so much for your help, it's been invaluable!
     
    Sam_Ooi likes this.
  8. Jiaquarium

    Jiaquarium

    Joined:
    Mar 22, 2020
    Posts:
    45
    Was using Pixel Perfect on Cinemachine and the Custom Canvas Scaler still didn't work for me and was using the viewport set by Pixel Perfect. Had to make a separate UI Camera with Pixel Perfect for all Canvases using Screen Space - Camera for them not to get squished.
     
    Last edited: Dec 31, 2020
  9. RevengerWizard

    RevengerWizard

    Joined:
    Feb 15, 2020
    Posts:
    15
    I've followed the setup above, but still the UI images aren't pixel perfect, even with the Custom Canvas Scaler. Is there any solution? I've searched for months and the nearest solution I've found is this package.
    The Pixel Perfect Camera is almost perfect, the only thing that remains is to make even the UI pixel perfected.
     
    enhawk likes this.
  10. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    just running into this problem @Sam_Ooi

    If I set the pixel perfect camera to reference resolution 398 x 224, and the canvas scaler to the same value, the canvas is drawn at different pixel ratios depending on the display screen size, meaning the pixels in the canvas and the camera don't match up. (iphone x screen size and 1080p screen size result in a scale mis match between the canvas pixels and the pixel perfect camera)

    Usually I use a custom render canvas for both game and ui, I wanted to try pixel perfect camera for a new project but it seems that theres a bug with the screen space canvas part of the setup.

    Using Unity 2019.4, 2D Pixel Perfect 2.1.0

    The custom canvas scaler attached above doesn't fix the issue for me, unless using both axes of "Crop Frame".

    Is there a way to make the canvas scaler and pixel perfect camera use the same scale (in essence, match up) without using Crop Frame?
     
    Last edited: Feb 1, 2021
  11. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Ended up using the solution posted above (ocias pixelart camera) as the Unity made plugin doesn't support canvas properly. Would advise anyone finding this to do the same for now, until Unity fix their pixel art camera.
     
    RevengerWizard likes this.
  12. Friskeh

    Friskeh

    Joined:
    Jun 27, 2019
    Posts:
    6
    This package completely broke my project and I'm still getting errors from it after I removed the package any ideas of how I can get rid of the errors. Literally did nothing other than add the package. https://i.imgur.com/cVmcJgn.png
     
    Last edited: May 23, 2021
  13. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    at the bottom of that page theres a comments section, Alexander seems quite responsive so give him a shout!
     
  14. Friskeh

    Friskeh

    Joined:
    Jun 27, 2019
    Posts:
    6
    I fixed this error, but the real problem I'm having is that when using that pixel perfect script if I change the size of a font it is either super blurry or unreadable, did you run into this issue at all? It's even happening in the example project provided with the package, and he's not responding on the website
     
  15. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Screen Shot 2021-05-24 at 22.04.50.png
    for fonts in fixed resolution pixelart projects, you almost certainly need to use a pixel art font in most cases. These can't be changed in point size as the data is only designed to support one point size clearly. For extra point sizes the font designer needs to make various fonts at different pixel sizes.

    I support font scaling in my asset store pack, it requires multiple canvases. I tried it out with ocias pixel perfect camera and works fine.
     
    Last edited: May 24, 2021
  16. Friskeh

    Friskeh

    Joined:
    Jun 27, 2019
    Posts:
    6
    Yeah if I use a different canvas than is selected by the Ocias Pixel Perfect Camera the font looks perfect I guess that works. Would just be nice to be able to use the same canvas as the rest of the UI assets