# Unity set RectTransform width independent from height

The usual way to set the width or height for a RectTransform is this one as far as I know : RectTransform.sizeDelta = new Vector2(...); . I want to set the width of my object in an EditorScript, so if I would use the mentioned method, I would automatically lock my height value in the editor. But I want to freely adjust my height and at the same time let the width be calculated from my script. So my problem is, that RectTransform.sizeDelta = new Vector2(...); is locking both values in the Editor.

• Why not RectTransform.sizeDelta = new Vector2(calculatedWidth, RectRansform.sizeDelta.y)? Sep 6 '16 at 1:32
• That's all the question is about, your line of code would lock the height in my editor, but I still want to adjust it. Sep 6 '16 at 6:08
• Tried it like this: pastebin.com/Rpeu3YmJ Don't see any height locking. Sep 6 '16 at 12:08
• Well shame on me for not trying your line of code... I did it like this : RectTransform.sizeDelta = new Vector2(calculatedWidth, RectRansform.rect.height); And that locked the height so I thought everything would do that... Thanks a lot! I would like to accept this as answer :) Sep 7 '16 at 5:52

RectTransform.sizeDelta = new Vector2(calculatedWidth, RectRansform.sizeDelta.y)