# What is RectTransform.sizeDelta?

**URL:** https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423
**Category:** UGUI
**Tags:** Scripting
**Created:** [June 9, 2017, 10:14pm UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423 "2017-06-09T22:14:37Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Shayan](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/shayan/32/539376_2.png) [@Shayan](https://discussions.unity.com/u/Shayan)
#### Post date: [June 9, 2017, 10:14pm UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/1 "2017-06-09T22:14:37Z")

</div>

Hello!  
My question is in the header. **I can’t get what’s the [RectTransform.sizeDelta](https://docs.unity3d.com/460/Documentation/ScriptReference/RectTransform-sizeDelta.html)?**  
I understood when anchors are same it shows a real size… But if it is not so I don’t get that it shows…  
**How does it calculate?**

---

<div class="post-metadata">

### Author: ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)
#### Post date: [June 10, 2017, 12:36am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/2 "2017-06-10T00:36:53Z")

</div>

From the docs you linked:  
If the anchors are together, sizeDelta is the same as size. If the anchors are in each of the four corners of the parent, the sizeDelta is how much bigger or smaller the rectangle is compared to its parent.

---

<div class="post-metadata">

### Author: ![Shayan](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/shayan/32/539376_2.png) [@Shayan](https://discussions.unity.com/u/Shayan)
#### Post date: [June 10, 2017, 9:01am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/3 "2017-06-10T09:01:37Z")

</div>

> [@methos5k](#):
>
> From the docs you linked:  
> If the anchors are together, sizeDelta is the same as size. If the anchors are in each of the four corners of the parent, the sizeDelta is how much bigger or smaller the rectangle is compared to its parent.

Yeah, I read it =) I mean what’s it? How can I calculate this value for different anchors positions manually? Just I need it to write a custom UI fitter.

---

<div class="post-metadata">

### Author: ![Laperen](https://avatars.discourse-cdn.com/v4/letter/l/71c47a/32.png) [@Laperen](https://discussions.unity.com/u/Laperen)
#### Post date: [June 10, 2017, 9:10am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/4 "2017-06-10T09:10:36Z")

</div>

You could try using RectTransfrom.rect.size instead.

---

<div class="post-metadata">

### Author: ![Shayan](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/shayan/32/539376_2.png) [@Shayan](https://discussions.unity.com/u/Shayan)
#### Post date: [June 10, 2017, 9:17am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/5 "2017-06-10T09:17:08Z")

</div>

> [@Laperen](#):
>
> You could try using RectTransfrom.rect.size instead.

Thank you, I’ll try!

---

<div class="post-metadata">

### Author: ![methos5k](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/methos5k/32/387158_2.png) [@methos5k](https://discussions.unity.com/u/methos5k)
#### Post date: [June 10, 2017, 9:47pm UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/6 "2017-06-10T21:47:29Z")

</div>

If you’re still looking for this, I’d just try to look at the values in a couple of tests and see if you can figure it out 🙂

---

<div class="post-metadata">

### Author: ![IgorAherne](https://avatars.discourse-cdn.com/v4/letter/i/a183cd/32.png) [@IgorAherne](https://discussions.unity.com/u/IgorAherne)
#### Post date: [June 11, 2017, 5:48pm UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/7 "2017-06-11T17:48:26Z")

</div>

right, so noone actually knows what the heck sizeDelta is…

---

<div class="post-metadata">

### Author: ![IgorAherne](https://avatars.discourse-cdn.com/v4/letter/i/a183cd/32.png) [@IgorAherne](https://discussions.unity.com/u/IgorAherne)
#### Post date: [June 11, 2017, 5:51pm UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/8 "2017-06-11T17:51:44Z")

</div>

Well, this will be useful:

[What sizeDelta is (Explanation with pictures)](https://stackoverflow.com/questions/44471568/how-to-calculate-sizedelta-in-recttransform)

[Modify the width and height of RectTransform](https://forum.unity3d.com/threads/modify-the-width-and-height-of-recttransform.270993/)

_[lzt120](https://forum.unity3d.com/members/lzt120.18048/) How Can I modify the width and height of RectTransform ?_  
**_[jashan](https://forum.unity3d.com/members/jashan.1579/)_** _Try this_  
_`csharp* *RectTransform rt = UICanvas.GetComponent (typeof (RectTransform)) as RectTransform; rt.sizeDelta = new Vector2 (100, 100);* *`_  
_where UICanvas is Canvas from scene._

or [this link](https://discussions.unity.com/t/551868/9) if you need to match the dimension of some other rec transform.

---

<div class="post-metadata">

### Author: ![Laperen](https://avatars.discourse-cdn.com/v4/letter/l/71c47a/32.png) [@Laperen](https://discussions.unity.com/u/Laperen)
#### Post date: [June 12, 2017, 12:47am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/9 "2017-06-12T00:47:40Z")

</div>

> [@IgorAherne](#):
>
> Well, this might be useful: [Modify the width and height of RectTransform](https://forum.unity3d.com/threads/modify-the-width-and-height-of-recttransform.270993/)
> 
> _[lzt120](https://forum.unity3d.com/members/lzt120.18048/) How Can I modify the width and height of RectTransform ?_  
> **_[jashan](https://forum.unity3d.com/members/jashan.1579/)_** _Try this_  
> _`csharp* *RectTransform rt = UICanvas.GetComponent (typeof (RectTransform)) as RectTransform; rt.sizeDelta = new Vector2 (100, 100);* *`_  
> _where UICanvas is Canvas from scene._

Pretty sure the OP knows the effect of modifying sizeDelta since hes asking how it calculates its value, which is dependent on the anchor values, and nobody should use such a an unreliable value as reference for anything.

As for your code example, there is no sense in getting the rectTransform component from the Canvas since its values are frozen.  
You can also shorten the GetComponent line to this:

```csharp
RectTransform rt = object.GetComponent<RectTransform>();

```

and

---

<div class="post-metadata">

### Author: ![suiri](https://avatars.discourse-cdn.com/v4/letter/s/c0e974/32.png) [@suiri](https://discussions.unity.com/u/suiri)
#### Post date: [January 15, 2018, 6:33am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/10 "2018-01-15T06:33:32Z")

</div>

hm

---

<div class="post-metadata">

### Author: ![Psyboyo](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/psyboyo/32/335429_2.png) [@Psyboyo](https://discussions.unity.com/u/Psyboyo)
#### Post date: [March 7, 2018, 12:19am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/11 "2018-03-07T00:19:25Z")

</div>

**sizeDelta:** If you made a search, and end up here for an explanation of what sizeDelta means, like _GetComponent().sizeDelta.y,_ then clear your mind.

Visualize a small PANEL, resting on top of a big CANVAS, it’s Parent object.  
In the PANEL’s Rect Transform component, there are 2 rectangles defined:

(a) The rectangle defined by its Anchors. Those triangles. Normally related to the Parent Object location and dimensions, in this case the CANVAS.

(b) The rectangle defined by its own size, the PANEL’s own dimension.

_sizeDelta = (b) - (a)_

That’s it. Because normally an interactive component like a Button, smaller in size compared to the object where it rests, like a Panel, and because of that, normally sizeDelta is a negative value. Button size - Panel size = a negative value, normally.  
You know the term Negative Space, used in general Design theory?  
Think of it, as the space NOT used by a Button resting on a Panel.

**Example:**  
How to find the height of a Panel, that is a Child of a Canvas that is a Camera overlay, thus screen sized. The Anchors of the Panel are related to the Canvas dimensions. Script is on the Panel object:

_panelHeight = Screen.height + this.GetComponent().sizeDelta.y;_

Remember, sizeDelta is normally negative so it reads more like this pseudo code:  
panelHeight = Screen.height - this.sizeDelta.y

Hope this helps you, drove me crazy for a while. _Cheers!_

**References:**

[![](https://europe1.discourse-cdn.com/unity/original/4X/8/7/5/875eedcd083f26c643fc7056a8dd91596c816d57.jpeg "Unity Tutorial: Bar Chart (Part 2)") ](https://www.youtube.com/watch?v=VhGxKDIKRvc)

[![](https://europe1.discourse-cdn.com/unity/original/4X/b/1/7/b17a60c221fcd37a385069ce26aae94786a2100a.jpeg "Rect Transform - Unity Official Tutorials") ](https://www.youtube.com/watch?v=FeheZqu85WI)

---

<div class="post-metadata">

### Author: ![a436t4ataf](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@a436t4ataf](https://discussions.unity.com/u/a436t4ataf)
#### Post date: [January 1, 2019, 9:55pm UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/12 "2019-01-01T21:55:53Z")

</div>

Ah! This explains why most of the google hits for “get the size of a RectTransform” say “sizeDelta” – and it works, the first few times. Then breaks completely forever.

(It “works” because if the (a) rect is zero, then b-a == b, equals the size)

Unity did a spectacularly bad job of naming these API elements 😄.

---

<div class="post-metadata">

### Author: ![dizzy2003](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dizzy2003](https://discussions.unity.com/u/dizzy2003)
#### Post date: [January 20, 2024, 3:50am UTC](https://discussions.unity.com/t/what-is-recttransform-sizedelta/667423/13 "2024-01-20T03:50:19Z")

</div>

I finally got around to understanding the chaos that is sizeDelta.  
Heres the function you need.

```csharp
public static void SetRectSize(RectTransform rt,Vector2 sizeWant)
{
    //The size delta is relative to the current size of the rectTransforms anchors
    //so if the anchor min and anchor max is the same, then no problem, sizeDelta gives the size you ask for
    // But if (rt.anchorMax-rt.anchorMin) is not 0,0 then you wont get the answer you expect
    // So you have to work out the size of the anchor (anchor max-min) by looking at the parents rect
    //then take that away from the size you actually want
  
    var rtp = rt.parent.transform as RectTransform;
    Vector2 sizep = rtp.rect.size;
    sizep.Scale((rt.anchorMax-rt.anchorMin));
    var sdelta = sizeWant-sizep;
    rt.sizeDelta = sdelta;
  
}

```
