Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question SetActive And Get SizeDelta value

Discussion in 'Scripting' started by D38LT, Mar 11, 2021.

  1. D38LT

    D38LT

    Joined:
    Feb 1, 2018
    Posts:
    2
    Please understand that I am not good at English before the text.

    I want to get RectTransform.sizeDelta.y which is inactive object.
    So I Use This Code

    Code (CSharp):
    1. void OnEnable()
    2.     {
    3.         this.transform.GetChild(1).gameObject.SetActive(true);
    4.         Debug.Log(this.transform.GetChild(1).gameObject.GetComponent<RectTransform>().sizeDelta.y);
    5.         this.transform.GetChild(1).gameObject.SetActive(false);
    6.     }
    But, It Returns 0...

    How Can I fix It?
     
  2. D38LT

    D38LT

    Joined:
    Feb 1, 2018
    Posts:
    2
    Well..
    I used a different method.

    Code (CSharp):
    1. this.transform.GetChild(1).gameObject.SetActive(true);
    2.         Debug.Log(this.transform.GetChild(1).gameObject.GetComponent<Text>().preferredHeight);
    3.         this.transform.GetChild(1).gameObject.SetActive(false);
    this code returns meaningful values

    Thanks