- Home /
RectTransform gives me different value depending on its enabled state when I hit play
I have a script where I set its property value based on RectTransform.
The weird behavior I am seeing now is that depending on whether this object was enabled or disabled when I first hit play, the returned value is different.
private void Start()
{
// Default values if not set by user is determined by the size of this object
if (PosUp == 0f) PosUp = gameObject.GetComponent<RectTransform>().rect.height; // sizeDelta.y;
if (PosDown == 0f) PosDown = 0f;
}
This script does the correct thing when this object was disabled when I hit play. This script does not do the correct thing when this object was enabled when I hit play.
What is going on? Why is RectTransform().rect.height different depending on the enabled state?
Also, this object has Content Size Fitter + Vertical Layout Group component attached to it. Every since I attached these two, I started seeing the behavior.
Thanks for any help!!
Your answer
![](https://koobas.hobune.stream/wayback/20220613052659im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rect.Contains and Rect.Overlap always return true 1 Answer
Aligning UI Elements in Code 0 Answers
Anchor doesn't affect objects inside of another object 0 Answers
Moving RectTransform over another RectTransform under GridLayout 0 Answers
change/scale child rectTransform with Parent (with video) 0 Answers