Page 1 of 1

Bark UI always under everything

Posted: Sat Sep 30, 2023 4:52 pm
by makovetksyi
Hi guys, I started use template Buble Bark UI, and all my barks under everything.
Does someone know how to fix that?

Re: Bark UI always under everything

Posted: Sat Sep 30, 2023 7:44 pm
by Tony Li

Re: Bark UI always under everything

Posted: Wed Oct 04, 2023 5:57 am
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

Re: Bark UI always under everything

Posted: Wed Oct 04, 2023 8:10 am
by Tony Li
Are you rendering the UI layer with a different camera that has a higher depth, as described in the link above?

Re: Bark UI always under everything

Posted: Wed Oct 04, 2023 9:49 am
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?

Re: Bark UI always under everything

Posted: Wed Oct 04, 2023 9:53 am
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.

Re: Bark UI always under everything

Posted: Thu Oct 05, 2023 6:15 am
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?

Re: Bark UI always under everything

Posted: Thu Oct 05, 2023 6:32 am
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.

Re: Bark UI always under everything

Posted: Thu Oct 05, 2023 8:56 am
by Tony Li
Hi,

Yes, please feel free to share the script here to help other people in the future. Thanks!

Re: Bark UI always under everything

Posted: Sat Oct 14, 2023 11:42 am
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!");
}
}
}