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

GridLayoutGroup children Z-values

Discussion in 'UGUI & TextMesh Pro' started by mmourlam, Sep 30, 2014.

  1. mmourlam

    mmourlam

    Joined:
    Jan 6, 2014
    Posts:
    5
    Image 2014-09-29 at 5.37.57 PM.png Image 2014-09-29 at 5.39.13 PM.png Image 2014-09-29 at 5.39.32 PM.png When adding children to a GridLayoutGroup the z-values for the children items (Rect Transform) are set to -3312.

    Below is single game object inside a grid container. Notice the Z value


    Properties for Grid (container game object)


    Properties for the Canvas


    Is there any way to set the Z-position of the children items? They are grayed out and disabled b/c the Grid Layout component is handling the positioning. Thanks in advance
     
  2. mmourlam

    mmourlam

    Joined:
    Jan 6, 2014
    Posts:
    5
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    What code are you using to add them?
     
  4. mmourlam

    mmourlam

    Joined:
    Jan 6, 2014
    Posts:
    5
    void GenerateLetterGrid()
    {
    int letterIndex = 0;

    for(int y=0;y<this.countY;y++)
    {
    for(int x=0;x<this.countX;x++)
    {
    Debug.Log("GenerateLetterGrid: "+letterIndex);

    GameObject newButton = (GameObject)GameObject.Instantiate((GameObject)Resources.Load("Letter Grid/Letter Item"));
    newButton.transform.parent = this.container.transform;

    //Set intial scale to 1.0 and z to 0
    newButton.transform.localScale = new Vector3(1.0f,1.0f,1.0f);
    newButton.transform.position = new Vector3(0,0,0);

    newButton.name = "Letter_"+letterIndex;

    //Letter item script
    LetterItem letterScript = newButton.GetComponent<LetterItem>();
    letterScript.letterIndex = letterIndex;
    letterScript.RandomizeLetter();

    //Add to our array
    this.letters.Add(newButton);

    letterIndex++;
    }
    }
    }
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    Need to use
    Code (csharp):
    1.  
    2. newButton.transform.SetParent (this.container.transform, false);
    3.  
     
    Last edited: Oct 1, 2014
    hotlabs likes this.
  6. MaxEden

    MaxEden

    Joined:
    Jun 22, 2013
    Posts:
    79
    Quick question:
    What the difference between
    Code (CSharp):
    1.  newButton.transform.SetParent (this.container.transform);
    and
    Code (CSharp):
    1.  newButton.transform.parent = this.container.transform;
    I didn't find it in the docs.
     
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    Sorry I should have said this.

    Code (csharp):
    1.  
    2. newButton.transform.SetParent (this.container.transform, false);
    3.  
    It's in the scripting reference how it differs.
     
    MaxEden likes this.
  8. hotlabs

    hotlabs

    Joined:
    Apr 11, 2021
    Posts:
    10
    thanks a lot from the future, I had lost one hour on this problem :)