Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Lines render infront of buttons

NaxNax
edited June 2016 in Questions And Answers

I'm trying to draw lines between buttons on my UI. I'm running into an issue where the lines appear in front of the buttons (I've attached an image showing this). I've tried setting the lines to render behind the buttons (by increasing the z position of the origin/destination) but it doesn't seem to be working.

Here's the script I'm using:

using UnityEngine;

// This script draws lines between elements of the Bowtie display
public class DrawLine : MonoBehaviour {
    private LineRenderer lineRenderer;
    public Transform origin, destination;

    void Start () {

        lineRenderer = gameObject.GetComponent<LineRenderer>();
        lineRenderer.SetWidth(.01f, .01f);
        lineRenderer.SetPosition(0, origin.position);
        lineRenderer.SetPosition(1, destination.position);
    }

    void Update()
    {
        lineRenderer.SetPosition(0, origin.position);
        lineRenderer.SetPosition(1, destination.position);
    }
}

Best Answer

Answers

  • A couple thoughts:
    1. Draw order might matter here. Draw your lines first, then the boxes.
    2. Alternatively, make sure that the shader you are using to draw your lines don't draw in front of depth, and make sure that the shader drawing your boxes does draw to the depth buffer.

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • NaxNax
    edited June 2016

    @Patrick
    1. I made a custom version of the standard shader for the lines and set the render queue to "Background" to ensure they are rendered first, however it didn't seem to work.
    2. Not sure how to check for this. Couldn't find anything relating to depth in the shader code.

  • DanglingNeuronDanglingNeuron ✭✭✭
    edited June 2016

    You have to set LineRendererObject.sortingLayerName ... First go to Tag&Layers window and add 2d sorting layers - sort their draw order. then assign appropriate layername to line renderers. then in the inspector go to your main canvas and assign the proper sorting layer there as well. the order of the layers will decide draw. I have achieved this without shader tweaking.

    Healthcare IT professional by day - Indie GameDev for UWP and mobile platforms by night

  • @DanglingNeuron I tried your method and it still doesn't seem to work. I set the line sorting layer to "Background" and I set the canvas sorting layer to "Default". Did I do something wrong?

    I forgot to mention that the lines render correctly when I run the scene in unity, they only appear in front when I run the app on the emulator.

    Canvas:

    public class DrawCanvas : MonoBehaviour
    {
        // Use this for initialization
        void Start()
        {
            gameObject.GetComponent<Canvas>().sortingLayerName = "Default";
        }
    }
    

    Line:

    // This script draws lines between elements of the Bowtie display
    public class DrawLine : MonoBehaviour {
        private LineRenderer lineRenderer;
        public Transform origin, destination;
        public Material material;
    
        // Use this for initialization
        void Start () {
    
            lineRenderer = gameObject.GetComponent<LineRenderer>();
            lineRenderer.SetWidth(.01f, .01f);
            lineRenderer.SetPosition(0, new Vector3(origin.position.x, origin.position.y, origin.position.z + 1f));
            lineRenderer.SetPosition(1, new Vector3(destination.position.x, destination.position.y, destination.position.z + 1f));
            lineRenderer.material = material;
            lineRenderer.sortingLayerName = "Background";
        }
    
        void Update()
        {
            lineRenderer.SetPosition(0, origin.position);
            lineRenderer.SetPosition(1, destination.position);
        }
    }
    
  • In your update loop, can you try:
    lineRenderer.SetPosition(0, origin.position+Vector3.forward * 0.1f);
    lineRenderer.SetPosition(1, destination.position + Vector3.forward * 0.1f);

    ===
    This post provided as-is with no warranties and confers no rights. Using information provided is done at own risk.

    (Daddy, what does 'now formatting drive C:' mean?)

  • NaxNax
    edited June 2016

    @Patrick Whoops meant to accept your answer. I'm an idiot. I attempted the same solution except I forgot to add it to the update function..

Sign In or Register to comment.