Unity UI Vertical Layout Group & Content Size Fitter

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Unity UI Vertical Layout Group & Content Size Fitter

Post by alfonso »

Hi Tony! i found a little issue when i use this two component in my speech bubble system, the idea of use this, is to fit the size of the bubble by the amount of text the npc will say to the player.

some times at the start of the scene when the dialogue initalice it seem that the panel is disabled before the vertical Layout Group get the values correctly and the content size set to 0 all children, if i disabled the CSUIBubble (my custom AbstractDialogueUI) and try starting 10 times and all goes fine but if i enabled at the seconds goes wrong and set sizes to cero.

who start disabling gameobject in the dialogueManager? and can i wait one frame to let the component get propertly the values?

thanks for all :D
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Unity UI Vertical Layout Group & Content Size Fitter

Post by Tony Li »

Hi Alfonso,

What about adding a script to the dialogue panel that has an OnEnable method? When the dialogue panel is enabled, you can recompute the layout.

Otherwise, you could override AbstractDialogueUI.Start. The base method hides everything:

Code: Select all

/// <summary>
/// Starts this instance by hiding everything. The only exception is if an alert message is
/// already showing; it keeps this message visible.
/// </summary>
public virtual void Start() {
    if ((UIRoot == null) || (Dialogue == null) || (QTEs == null) || (Alert == null)) {
        enabled = false;
    } else {
        UIRoot.Show();
        Dialogue.Hide();
        QTEs.Hide();
        if (!Alert.IsVisible) Alert.Hide();
        if (IsOpen) Open();
        if (!(Alert.IsVisible || IsOpen)) UIRoot.Hide();
    }
}
You could create a subclass like this:

Code: Select all

public override void Start() {
    StartCoroutine(WaitToStart());
}

private IEnumerator WaitToStart() {
    yield return null; // Wait 1 frame first.
    base.Start();
}
alfonso
Posts: 104
Joined: Mon Jul 13, 2015 6:31 am

Re: Unity UI Vertical Layout Group & Content Size Fitter

Post by alfonso »

as I imagined a frame waiting fixes everything

great as always tony :D
Post Reply