Search Unity

Question How to nest UI elements in empty game objects without breaking anchoring? (canvas grandchildren)

Discussion in 'UGUI & TextMesh Pro' started by karderos, Apr 18, 2023.

  1. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    If my UI buttons are directly children of the canvas everything stays correctly anchored, no matter how I change the size of the screen in free aspect. My canvas settings are like so:

    Untitled.png

    However if I create an empty game object( which by nature also has a rect transform ) for the sake of organization, and place the buttons as children of the empty game object, the anchoring breaks and only works well on the Y axis.

    On the canvas scaler if i switch the slider for X, then they anchor correctly only on the X axis, with the slider on half its incorrect for both axis as both clip through the screen

    I want to emphasize that my problem is only for objects that are grandchildren of the canvas

    children of the canvas anchor perfectly both on X and Y

    however grandchildren only anchor on either Y or X based on how the slider of my canvas scaler is set

    Is there a simple fix for this?
     
    Last edited: Apr 18, 2023
  2. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    i found the fix, set the anchor of the parent to full stretch