Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[BUG] LineRenderer invisible when changing position via script.

Discussion in 'General Graphics' started by Wattosan, Apr 16, 2018.

  1. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    450
    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.

    Code (CSharp):
    1. private void Update()
    2.     {
    3.         if (laserDotActive) { FireLaserDot(); }
    4.     }
    5.  
    6.     void FireLaserDot()
    7.     {
    8.         RaycastHit hit;
    9.         if (Physics.Raycast(laserStartTransform.position, laserStartTransform.forward, out hit))
    10.         {
    11.             // laserDot.transform.position = hit.point;
    12.             laserDotLR.SetPosition(0, hit.point);
    13.             laserDotLR.SetPosition(1, hit.point);
    14.         }
    15.     }

    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!
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    Hi, a line of zero length will not be visible.
     
  3. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    450
    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.
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    If you want to attach a unitypackage I will try to understand it.
     
  5. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    450
    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.
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    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,
     
  7. qyalexwen

    qyalexwen

    Joined:
    Jul 29, 2018
    Posts:
    8
    Check the Z value. If the Z value is at or behind the camera, you won't see the line.