Canvas Scaler: Runtime adding prefab to layout differs from editor

Hi.

  1. Programmatically adding prefab items to a vertical layout differs from adding them through the editor
  2. But only when the canvas scaler is set to “Scale with screen size”

In the first attached image

  1. The first line of text is added to the editor before startup and is not part of the vertical layout
  2. The next 3 lines are added programmatically at runtime
  3. The last line is added in the editor after pausing the game. Its position and text size is what I expected for the other 3 lines.

The second attached image is correct and what it looks like without the canvas scaler.

Anyone know what I could be doing wrong ? Is this a bug ?

I’m using unity 4.6.1
Thanks !

1925614--124384--textsize.png
1925614--124386--textsize_correct.png

Ok,
My bad, Transform.SetParent’s second parameter should be false, then the correct scaling and position is applied.