Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using a Grid with composite prefabs

Discussion in 'UGUI & TextMesh Pro' started by dogfacedesign, Nov 5, 2018.

  1. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    I posted this originally in the wrong forum, as I didn't see the UI subforum at first. I have requested an admin delete the original, so recreating it here in hopes of soliciting some guidance from Unity/UI gurus out there.

    So I have a test grid set up, and it works fine with single items in each cell (image, text, etc.). But, if I try to put something in there like a prefab that has an image and a text label in it, it doesn't seem to work (they all sort of stack up on top of each other instead of being spread out in the grid).

    When I say "composite prefabs", I mean prefabs with more than one GameObject in it. For example:

    GameObject (just a Container or "row")
    ---- GameObject (Image)
    ---- GameObject (Text/Label)

    Is this normal behavior for the grid component? Thanks in advance for any suggestions/guidance!
     
  2. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    When I said "row" above, I meant "cell" .... blush!
     
  3. leftshoe18

    leftshoe18

    Joined:
    Jul 29, 2017
    Posts:
    61
    It sounds like your prefab isn't set up properly. I use this method for most of my dynamically generated UI elements and haven't had any problems.

    How is your container set up? How are the child objects anchored?
     
  4. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    They have relative offsets to the cell container, I would think they would be fine. I will explore it further - anchoring may indeed be necessary.