2
\$\begingroup\$

I am making an app that has a custom viewport Rect like so:

enter image description here

When I check the sizes of this viewport rectangle in pixels with Camera.pixelHeight; Camera.pixelWidth, I get the following values: 743px, 770px.

This looks correct.

Now when I check my canvas in the Editor, I see the following values for the width and height:

enter image description here

Now I have a script that gets the width and height of the canvas. This is correct: I get again the 743px and 770px. But when I position my UI element, it is outside because the positioning refers back the the incorrect values displayed in the canvas rectangle transform properties.

What is happening here and how do it make the canvas use the correct values?

\$\endgroup\$
  • \$\begingroup\$ I haven't been able to reproduce this situation in my own tests. The width and height values displayed in the recttransform are reliably matching the pixel size of the canvas & camera viewport. In any case, the particular symptom you're describing - that positioning the UI elements is leading to the wrong positions - can have other causes, depending on how you're setting their positions. Can you show us the code you're using to position a particular element, and compare the expected position against the in-game effect? \$\endgroup\$ – DMGregory Jul 25 '18 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.