Line renderer position?

Hello. When using the unity line renderer, is there a way to make the positions that the line uses as nodes to another objects transform position instead of a vector 3 position (I want the line to move)? Thanks

Old question, but for future reference, you can uncheck the default “Use World Space” option in the inspector to have the Positions relative to the transform on the GameObject.

You can also set it in code as such (C# code on a MonoBehaviour):

LineRenderer myLineRenderer = GetComponent<LineRenderer>();
myLineRenderer.useWorldSpace = false;

first set "use world space " to off in inspector
set element 0 to 0,0,0
if targetObject is moving put this in update or coroutine

Use SetPosition in an Update() function, with the second parameter being the transform position of whatever you're tracking.

You could make the line renderer a child object to the thing you want it to follow. Then it would automatically go everywhere the parent went.

My solution is bake the line into mesh, then I can easily move that line

Here is the code:

public static void BakeLineDebuger(GameObject lineObj)
    var lineRenderer = lineObj.GetComponent<LineRenderer>();
    var meshFilter = lineObj.AddComponent<MeshFilter>();
    Mesh mesh = new Mesh();
    meshFilter.sharedMesh = mesh;

    var meshRenderer = lineObj.AddComponent<MeshRenderer>();
    meshRenderer.sharedMaterial = s_matDebug;


Make sure lineObj has LineRenderer component.