Pixel Perfect while Scale With Screen Size

Hello!

Is there a way to make the “Pixel Perfect” mode of a root canvas set to “Scale With Screen Size” work as if it was set to “Constant Pixel Size”?

I explain: I want the behavior of “Scale With Screen Size” (having elements that keep 100% of the width of the parent and still keep the same ratio width/height without using additional scripts) but I also want that same element (or a child) to have a border of 1 real pixel (through an outline or a sprite border) independently of the window resolution.

Also I wonder if it is a bug that enabling “Pixel Perfect” has an effect only with “Constant Pixel Size”.

Thanks.
Unity 5.1.3f1

This is not the regular behaviour, but with some simple scripting (a few lines) you can get this result by setting the referencePixelsPerUnit property of the CanvasScaler to compensate for the Canvas scaleFactor.

Something like referencePixelsPerUnit = 100 / canvas.scaleFactor;

Hope that helps!

Thank you for your reply!

In fact modifying the scale is the problem, and compensating with the referencePixelsPerUnit doesn’t work.
With the root canvas scale set to 1, and 100 referencePixelsPerUnit, the child Image (with a 1px border of a sliced Sprite) looks pixel perfect:
2299567--154819--upload_2015-9-17_15-14-46.png
With the root canvas scale set to 2, referencePixelsPerUnit set to 50:
2299567--154816--upload_2015-9-17_15-13-55.png
With the root canvas scale set to 2, referencePixelsPerUnit set to 50.1:
2299567--154817--upload_2015-9-17_15-14-12.png
These results were obtained inside the Editor (Game tab during Play). All values are round.
Components of root canvas:
2299567--154820--upload_2015-9-17_15-15-19.png
RectTransform of immediate Image child:
2299567--154821--upload_2015-9-17_15-16-10.png
The Sprite asset has 100 Pixels Per Unit.

Well, I assume it’s better than not using it? E.g. using Canvas scale factor of 2 while keeping referencePixelPerUnit at 100 I’d expect your lines would be twice as thick as they should be.

The fact they they still don’t align perfectly is unfortunate though. Maybe it’s a bug. The best option is to file a bug report including repro project and reproduction steps.