UI on active/inactive game objects

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
micio.del.cheshire
Posts: 5
Joined: Wed Sep 02, 2020 9:49 am

UI on active/inactive game objects

Post by micio.del.cheshire »

I'm using a Custom Dialogue UI already in a scene. The Ui is on a panel on a canvas, because the panel can be moved around. It works fine until I start playing with the active status of the UI's parent GameObject. I need to toggle on and toggle off its active status, during the game. Simply using CanvasGroup to simulate its presence doesn't do the trick.

But I discovered that the DialogueSystem doesn't like it very much when its Dialogue UI isn't active.
If the UI isn't active when the dialogue starts, it creates its own version under DialogueManager's canvas.
If the UI go inactive during a dialogue, I got null errors in the log.

I try to make my way under the hood, but my coding skills aren't enough to customize the behaviour this way.

Is there a way in which I can have a UI in a scene (so I can move it around) and in which I can deactivate and activate the gameObject containing the UI, even during a conversation? (not a problem if I have to pause/unpause it).

Thanks for the help
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: UI on active/inactive game objects

Post by Tony Li »

Hi,

Add a Canvas component and GraphicRaycaster component to the parent panel. Nested canvases are allowed, and in fact they're better for performance because when a UI element changes, the UI only needs to recompute the layout for everything contained in the canvas.

To disable the parent panel, disable the Canvas component.
micio.del.cheshire
Posts: 5
Joined: Wed Sep 02, 2020 9:49 am

Re: UI on active/inactive game objects

Post by micio.del.cheshire »

Tony Li wrote: Thu Sep 03, 2020 9:55 am To disable the parent panel, disable the Canvas component.
What if I need the Canvas to be active?
The canvas contains some panels (think of them as windows of an operating system).
This way I can focus a panel and it gets moved in the hierarchy so the last one is the window above the others.
One of these panels has the Dialogue UI in it. If I put it in a Canvas of its own, the other panels aren't able to overlap it.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: UI on active/inactive game objects

Post by Tony Li »

In that case, your can either set the canvas sort order or move the StandardDialogueUI component to a GameObject that stays active. It doesn't have to be on your actual visible UI structure. Just point its Dialogue Panel field to the top level d UI panel.
micio.del.cheshire
Posts: 5
Joined: Wed Sep 02, 2020 9:49 am

Re: UI on active/inactive game objects

Post by micio.del.cheshire »

I feel dumb.
Usually when I see a prefab I don't mess it up... I didn't think to move the actual script of the Dialogue UI on a ever active gameobject OTHER than the actual prefab.

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

Re: UI on active/inactive game objects

Post by Tony Li »

No problem. UI scripts often assume they're on the UI itself, so it's usually a good idea to leave them where they are. The StandardDialogueUI doesn't make this assumption, though, for the very reason in this thread.
Post Reply