Bark UI always under everything

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Bark UI always under everything

Post by makovetksyi »

Hi guys, I started use template Buble Bark UI, and all my barks under everything.
Does someone know how to fix that?
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Bark UI always under everything

Post by makovetksyi »

Tony Li wrote: Sat Sep 30, 2023 7:44 pm Hi,

Please see: How To: Make World Space Canvas Appear On Top Of Everything Else

I copied the template and UI layer was already - you can see it screenshot
Attachments
Screenshot 2023-10-04 at 11.56.22.png
Screenshot 2023-10-04 at 11.56.22.png (752.16 KiB) Viewed 455 times
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Bark UI always under everything

Post by Tony Li »

Are you rendering the UI layer with a different camera that has a higher depth, as described in the link above?
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Bark UI always under everything

Post by makovetksyi »

Tony Li wrote: Wed Oct 04, 2023 8:10 am Are you rendering the UI layer with a different camera that has a higher depth, as described in the link above?
I have only one camera in my scene. Do I really need to create another?
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Bark UI always under everything

Post by Tony Li »

If you want to use world space UIs, then yes. That's the correct way to do it. The process is documented in the link above.

Alternatively, you can switch to using a screen space UI. The Dialogue System Extras page has a "UI Smooth Follow" example that demonstrates how to do this.
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Bark UI always under everything

Post by makovetksyi »

Tony Li wrote: Wed Oct 04, 2023 9:53 am If you want to use world space UIs, then yes. That's the correct way to do it. The process is documented in the link above.

Alternatively, you can switch to using a screen space UI. The Dialogue System Extras page has a "UI Smooth Follow" example that demonstrates how to do this.
Got it. But how can I attach this script to bark prefab? If prefab is spawned as clone, and I dont have it in my NPC object?
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Bark UI always under everything

Post by makovetksyi »

I wrote my own script, and solve the problem.
Now - all barks are spawned under needed NPC.

If you want - I can share script and you use it.
User avatar
Tony Li
Posts: 21679
Joined: Thu Jul 18, 2013 1:27 pm

Re: Bark UI always under everything

Post by Tony Li »

Hi,

Yes, please feel free to share the script here to help other people in the future. Thanks!
makovetksyi
Posts: 13
Joined: Fri Sep 22, 2023 7:35 pm

Re: Bark UI always under everything

Post by makovetksyi »

Here:

using System;
using UnityEngine;
using UnityEngine.UI;

public class BarkAdjustCanvasAndPosition : MonoBehaviour
{
public Canvas canvas;
//public GameObject mainPanel;

void Start()
{
// Find the main camera in the scene
Camera mainCamera = Camera.main;

// Check if we found the main camera
if (mainCamera != null)
{
// Set Canvas rendering mode to Screen Space - Camera
canvas.renderMode = RenderMode.WorldSpace;

// Set the Render Camera to the main camera
canvas.worldCamera = mainCamera;

// Change the sorting layer of the Canvas to "Top"
canvas.sortingLayerName = "NPC";

// Find the parent GameObject (npc) that contains the Canvas
GameObject npc = transform.parent.gameObject;
Transform mainPanelTransform = canvas.transform.Find("Main Panel");
// Check if the parent GameObject (npc) and mainPanel variable are assigned
if (npc != null)
{
// Set the position of mainPanel under the parent GameObject (npc) (+2 units up)
Vector3 mainPanelPosition = new Vector3(npc.transform.position.x, npc.transform.position.y + 1f);
mainPanelTransform.position = mainPanelPosition;
}
else
{
Debug.LogError("Parent GameObject (npc) or mainPanel variable not assigned!");
}
}
else
{
Debug.LogError("Main Camera not found!");
}
}
}
Post Reply