Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Dynamic chat bubble with fixed left edge: works in "game" preview, not at runtime

Discussion in 'UGUI & TextMesh Pro' started by Selek-of-Vulcan, Feb 18, 2024.

  1. Selek-of-Vulcan

    Selek-of-Vulcan

    Joined:
    Sep 23, 2021
    Posts:
    78
    I'm trying to have a character portrait, whose position is fixed, bark comments from the left edge of the screen. I'd like to give him a chat bubble that changes size depending on the length of his comments. (I'm using a TMP for the text; its parent bubble is an Image with a square sprite.) With a Vertical Layout Group, the bubble does change size, but its left edge moves around, keeping the text centered. To fix this, I tried adding a parent panel with a Horizontal Layout Group. This does work when I preview it in game mode: if I type longer text, the bubble expands rightward only, which is what I want.

    But when I run the game, as opposed to just previewing it in Game mode in the editor, the text reverts to its behavior without the parent Horizontal Layout Group. This seems very odd to me. Usually if I preview something in Game mode, it works fine at runtime too.

    Any suggestions? Maybe I'm not setting this up optimally? Also, I do want to show/hide the bubble frequently, but I get this issue even if I keep the bubble visible constantly. Thanks in advance.
     
  2. Selek-of-Vulcan

    Selek-of-Vulcan

    Joined:
    Sep 23, 2021
    Posts:
    78
    Perhaps I need to rephrase my question. Is there a way to create a text bubble that resizes dynamically but whose left edge remains fixed?

    Perhaps I've asked in the wrong forum? Should I try the general forum or the scripting forum or something?
     
  3. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    712
    Make sure your anchors are set properly, when resizing something the anchors will determine in which directions the content will grow.