Correct usage of Dialogue Manager prefab and linking to UI

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
suisei
Posts: 10
Joined: Tue Aug 22, 2023 7:45 am

Correct usage of Dialogue Manager prefab and linking to UI

Post by suisei »

Hello.

I'm trying to embed Dialogue System to my game. I have a question about correct usage of Dialogue Manager prefab.

In my old GameObject hierarchy I have 'UI' prefab, and somewhere inside it i have 'DialogueUI' GameObject (prefab, but it is not instantiated in runtime, but just preserve inside UI prefab). When I'm working with single scene, I can just drag Dialogue Manager to scene and link my Dialogue UI to it (without canvas link). It works when I have 1 scene.

But I have multiple scenes. Documentations says I should use Dialogue Manager prefab as a singleton with "don't destroy on load". And drag Dialogue Manager to MainMenu. And here is the problem: in MainMenu Dialogue Manager does not have a link to UI, because MainMenu does not have dialogues (obviously).

Each scene loads UI prefab on scene loading, including dialogue UI. So on every scene I have new instance of dialogue UI and I have to tell Dialogue Manager (which is constant between scenes) what is the current dialogue UI now.

I tried to write a custom script which assigns Dialogue UI to Dialogue Manager OnAwake, but this solution does not work.

Therefore I see 2 options.

1. Give up on my old UI hierarchy, use Canvas inside Dialogue Manager, link child canvas and UI prefab to Dialogue Manager, and refactor things to work with this approach.

2. Insert Dialogue Manager into the UI prefab. But in this case Dialogue Manager will not be one object between all scenes, but recreated on every scene with UI. I'm not sure if this is good, may be it is mandatory for it to preserve some runtime data between scenes, and may be this solution will break some functionality.

May be I'm missing something and there is more options. So I'm looking for advices what will be the best solution in my case.
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by Tony Li »

Hi,

If you don't want to use option #1 (use Canvas inside Dialogue Manager), you can assign the dialogue UI in a Start() method. For example, add this script to your dialogue UI:

UseThisDialogueUI.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class UseThisDialogueUI : MonoBehaviour
{
    void Start() { DialogueManager.UseDialogueUI(this.gameObject); }
}
suisei
Posts: 10
Joined: Tue Aug 22, 2023 7:45 am

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by suisei »

Thanks for reply.

I have tried this approach. But if I set 'Dialogue UI' in DialogueSystemController to None, and add your script to my DialogueUI, DialogueManager spawns 'Default Dialogue UI' object as its child, and I got millions of errors about using standard Unity Input (in my project I use Input System instead)

Image

Image

Seems like Dialogue Manager creates default UI if no UI provided, but I cannot find checkbox to disable this.
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by Tony Li »

Hi,

You can assign the Basic Standard Dialogue UI prefab to the Dialogue Manager's Display Settings > Dialogue UI field to prevent it from creating a default UI.
suisei
Posts: 10
Joined: Tue Aug 22, 2023 7:45 am

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by suisei »

Your advice helped me, it works!

But in this case Basic Standard Dialogue UI instantiates anyway:

Image

(Dialogue Manager has correct link to my UI, not this default instantiated one)

Is it okay?
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by Tony Li »

Yes, that's fine. It will be there, but it won't be used. It doesn't use any extra textures, so it has basically no memory footprint.
suisei
Posts: 10
Joined: Tue Aug 22, 2023 7:45 am

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by suisei »

Thank you very much!
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Correct usage of Dialogue Manager prefab and linking to UI

Post by Tony Li »

Glad to help!
Post Reply