[BUG] LineRenderer invisible when changing position via script.

Hello,

My created line renderer is visible in these cases:

  1. No play mode, game view, scene view.
  2. Play mode, game view, scene view.

However, is not visible when changing the position in script in either FixedUpdate or Update modes.

Laser Dot Script

private void Update()
    {
        if (laserDotActive) { FireLaserDot(); }
    }

    void FireLaserDot()
    {
        RaycastHit hit;
        if (Physics.Raycast(laserStartTransform.position, laserStartTransform.forward, out hit))
        {
            // laserDot.transform.position = hit.point;
            laserDotLR.SetPosition(0, hit.point);
            laserDotLR.SetPosition(1, hit.point);
        }
    }

If I select the line renderer game object in the hierarchy, its position IS updated accordingly. This I can see thanks to the object gizmos in scene view, and Element 0 and Element 1 changing in the inspector.
However, the line renderer itself is not visible anymore. The line renderer’s both points are set to the same location because I am trying to create a laser dot.
Also, I am using the default particle as the material and color is set to red (1,0,0). Width is 1, using world space, no loop.

Using SteamVR, Unity version 2017.3.0f3.

Thanks!

Hi, a line of zero length will not be visible.

But it is visible in non play-mode or even in playmode when I have not changed the initial positions (0,0,0) of both position elements.

If you want to attach a unitypackage I will try to understand it.

You were correct, putting the end and start points at the same position makes the line invisible. However, try this:

  1. Create a new gameobject
  2. Add line renderer component
  3. Make sure the 2 position elements are at the same coordinates

Have a look through the scene view or even the camera view. You can see the line renderer. It is visible, even though the positions are same. You can even start playmode, and the linerenderer is still visible. Only after changing the positions in Play mode, through script, does the line disappear.

I just tried this… and… no it’s not, not for me at least. If you want to report a bug for it, QA can help establish what it is about your setup that is causing this to happen. (https://unity3d.com/unity/qa/bug-reporting)

Thanks,

Check the Z value. If the Z value is at or behind the camera, you won’t see the line.