ResponsePanel Spacing Problem/Bug?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
redisthecolor
Posts: 9
Joined: Sat Dec 12, 2020 11:56 am

ResponsePanel Spacing Problem/Bug?

Post by redisthecolor »

Hi there,

I am currently customizing the response panel now and facing a bit of a problem.

So the response panel contains of button that fits the size of the text (so no max or min width / height)

In the editor, the spacing works well: it means if I duplicate the button several time and change the text inside, the space between button is the same.

But in the runtime I face the problem that the button has no space at all. And if I update the child alignment, then the spacing is correct. See the following gif: I even changed back to the original child alignment and the spacing is still correct.

Image
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: ResponsePanel Spacing Problem/Bug?

Post by Tony Li »

Hi,

There shouldn't be any difference in UI between editor and build, other than a different game view resolution. Test different Game view sizes to make sure the resolution isn't the issue. Keep in mind that when you play a build, it plays from the first scene in build settings. Make sure that scene, or whichever scene has the first instance of the Dialogue Manager GameObject, points to the right dialogue UI and not an older version.
redisthecolor
Posts: 9
Joined: Sat Dec 12, 2020 11:56 am

Re: ResponsePanel Spacing Problem/Bug?

Post by redisthecolor »

Just did a little digging. I am not the only one who has this problem. Probably not Dialoge Systems related. Since it has something to do with content size fitter that needs to be force updated

redisthecolor
Posts: 9
Joined: Sat Dec 12, 2020 11:56 am

Re: ResponsePanel Spacing Problem/Bug?

Post by redisthecolor »

So I created a script called ForceRebuildUI and add them to the ResponsePanel.

Code: Select all

public class ForceRebuildUI : MonoBehaviour
{
    //Mark the given RectTransform as needing it's layout to be recalculated during the next layout pass.
    public RectTransform rect;

    private void Update()
    {
        LayoutRebuilder.MarkLayoutForRebuild(rect);
    }
}
I have to put it in Update since it doesn't work inside OnEnable or Start. Do you think this is memory expensive? Or do you have better solution for me?

Thanks.
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: ResponsePanel Spacing Problem/Bug?

Post by Tony Li »

Hi,

That's going to affect performance. Try adding a script like this to the Dialogue Manager instead:

RebuildDialogueUI.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class RebuildDialogueUI : MonoBehaviour
{
    void OnConversationResponseMenu(Response[] responses)
    {
        var rect = ((DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements.defaultMenuPanel.panel.GetComponent<RectTransform>())
        LayoutRebuilder.MarkLayoutForRebuild(rect);
    }
}
It will only issue the rebuild once when setting up each menu.
redisthecolor
Posts: 9
Joined: Sat Dec 12, 2020 11:56 am

Re: ResponsePanel Spacing Problem/Bug?

Post by redisthecolor »

Thanks. It works as well! :!:
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: ResponsePanel Spacing Problem/Bug?

Post by Tony Li »

Glad to help!
Post Reply