1
\$\begingroup\$

My canvas scaler does not work when the UI is instantiated dynamically.

It does work well in iPhone 6.5 inch simulator:

Correct scaling behaviour

The problem is when I use 5.5 inch or smaller simulator:

Incorrect scaling behaviour

It does not follow the Canvas scaler to resize.

How can I fix this problem?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

set worldPositionStays to false as a second parameter to SetParent.

YourUI.transform.SetParent(canvas.transform, false);

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This answer would be even better if it briefly explained why this fixes the problem. \$\endgroup\$
    – DMGregory
    Commented Oct 3, 2022 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .