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

Question Trying to use vertical layout group for dynamically shaped objects.

Discussion in 'UGUI & TextMesh Pro' started by Divinitize1, Feb 7, 2023.

  1. Divinitize1

    Divinitize1

    Joined:
    May 27, 2019
    Posts:
    99
    See below image, I am making a text message type system, each new message will appear ontop of the other ones before eventually fading out.
    The issue i have is that i cannot seem to get the scaling/spacing to work for things that are different sizes, i don't know if it's because i dont have a content size fitter in the correct place or what but any help would be greatly appreciated.

    Here is my setup

    -Empty game object (holder) - Has verticle layout group & content size fitter with vertical fit preffered size
    --Empty holder for all elements(prefab, text, BG, icon) - only has the script to run the text feature
    ---Text message BG, has vertical layout group and content size fitter with preffered size, this expands as more text is added vertically
    ----Text and icon in here with no UI layout elements or scripts.




    UnityUIIssue.png
     
  2. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    595
    Seems like your problem is in "--Empty holder for all elements". Do I understand correctly that you have one of those for each text message. For the top level "-" layout to work correctly, the second level item "--" need to resize together with third level item "---".

    If you made "--" to execlude some elements from being affected by vertical layout of the text message that's not necesarry. You can exclude items from being affected by layout by adding "Layout element" component and marking "ignore layout" checkbox.

    If you created "--Empty holder" because you got a warning that content size fitter can't be placed inside a layout. Then you need to remove the content size fitter. It's a bit unintuitive but content size fitter is only necesarry for objects whose parent's don't have layout, for objects inside a layout the layout can do the same thing as content size fitter (if configured correctly). If you think about it a bit more there is some logic of not being able to have two different components (parent layout and the content size fitter) both of which try to control size of same rect transform. Confusing part is that even when "control child size" is disabled the conflict is still there.
     
  3. Divinitize1

    Divinitize1

    Joined:
    May 27, 2019
    Posts:
    99
    Thanks you've actually been very helpful, i removed the --Empty holder so each of the text prefabs root is the BG of the text. The spacing is more or less working, the issue i have now is i cant for the life of me get the new instantiated messages to grow upwards in the layout group, they're spawning in and running off down screen, ive spent over an hour trying to fix this now and any slight change i make breaks the whole setup. Id never thought id have this much trouble with a UI element, I don't suppose you would be willing to help out over discord at all? you seem to know your stuff and im at my wits end. and without uploading like 10+ screenshots of each of my elements and what components they have it's hard to do it on the forum. EDIT: I think i finally figured it out, by just duplicated many texts, it eventually stopped grown downwards and started going up, i then used that to find the sweet spot on the bottom padding and that seemed to do the trick. Thanks!

    I also want to mention i literally could not get this to work without a content size fitter on the main TextMessage prefab, even though it gives the caution error. the background of the texts were not growing as the text amount grew.
     
    Last edited: Feb 8, 2023