Lesson 42 +10 XP

Trail & Line Renderers

Trail & Line Renderers

Unity provides components to draw vector lines and dynamic path trails directly in 3D or 2D space.

The Line Renderer

The Line Renderer draws a line between an array of two or more points.

  • You can set the number of points and coordinate locations in the Inspector or via code.
  • Useful for drawing laser sights, ropes, UI connectors, or debug lines.
private LineRenderer line;

void Start()
{
    line = GetComponent<LineRenderer>();
    line.positionCount = 2;
    line.SetPosition(0, Vector3.zero);
    line.SetPosition(1, Vector3.forward * 5f);
}

The Trail Renderer

The Trail Renderer spawns a fading trailing ribbon behind a moving GameObject.

  • Useful for weapon projectiles (bullets, fireballs) or vehicle tire tracks.
  • Time: Controls how long the trail remains visible (in seconds) before fading.
  • Width Curve: Allows defining a curve to shrink the trail from head to tail.

Both components require a Material to render. Make sure to assign a material that uses a mobile/particle shader to support color transparency.

TL;DR

  • Line Renderer draws static or dynamic line segments between coordinates.
  • Trail Renderer leaves a fading ribbon path behind moving objects.
  • Adjust the Time property to change trail length.
  • Both components require a Material to render correctly.