codeAPI Reference

s&box Tracer: Projectile trail renderer

calendar_today May 12, 2026 schedule ~2 min read person PatrickJr verified 50

Tracer Renderer Component API Reference

Tracer is a Renderer component that creates a tracer effect (like bullet trails) that travels from its world position to an end point. It implements Component.ExecuteInEditor and Component.ITemporaryEffect for editor preview and automatic cleanup.

Type Signature

CSHARP
public sealed class Tracer : Renderer, Component.ExecuteInEditor, Component.ITemporaryEffect
{
    [Property, Feature("Tracer")] public WorldPoint EndPoint { get; set; }
    
    [Property, Feature("Tracer")] public float DistancePerSecond { get; set; } = 1.0f;
    [Property, Feature("Tracer")] public float Length { get; set; } = 100.0f;
    [Property, Feature("Tracer")] public float StartDistance { get; set; } = 200.0f;
    
    [Property, Feature("Tracer")] public Gradient LineColor { get; set; }
    [Property, Feature("Tracer")] public Curve LineWidth { get; set; }
    [Property, Feature("Tracer")] public SceneLineObject.CapStyle StartCap { get; set; }
    [Property, Feature("Tracer")] public SceneLineObject.CapStyle EndCap { get; set; }
    
    [Property] public bool Opaque { get; set; } = true;
    [Property] public bool CastShadows { get; set; } = true;
    
    [Property, FeatureEnabled("Light", Icon = "💡")] public bool EnableLight { get; set; }
    [Property, Feature("Light")] public Gradient LightColor { get; set; }
    [Property, Feature("Light")] public Curve LightRadius { get; set; }
    [Property, Feature("Light"), Range(0, 1)] public float LightPosition { get; set; } = 0;
    
    [Property] public Material Material { get; set; }
}

Properties

Position

Speed

Rendering

Light

Component Interfaces

Behavior

  • Creates a SceneLineObject for rendering the tracer line
  • Travels from WorldPosition to EndPoint at DistancePerSecond
  • Renders a gradient-colored line with varying width
  • Optionally creates a ScenePointLight that follows the tracer head
  • Automatically disables when the tracer reaches the end point
  • Loops in editor mode for preview purposes

WorldPoint Struct

CSHARP
public struct WorldPoint
{
    [KeyProperty] public Vector3 Origin { get; set; }
    public GameObject Parent { get; set; }
    
    public Vector3 Get();
    public static implicit operator WorldPoint(Vector3 v);
}

WorldPoint represents a point that can be either a world-space Vector3 or a local-space point relative to a parent GameObject.

Usage

CSHARP
// Create a tracer at the muzzle position
var tracer = GameObject.AddComponent<Tracer>();
tracer.WorldPosition = muzzlePosition;
tracer.EndPoint = hitPosition;
tracer.DistancePerSecond = 5000f;
tracer.Length = 200f;
tracer.LineColor = new Gradient(
    new Gradient.ColorFrame(0, Color.Yellow),
    new Gradient.ColorFrame(1, Color.Red.WithAlpha(0))
);
tracer.EnableLight = true;
tracer.LightColor = new Gradient(
    new Gradient.ColorFrame(0, Color.Orange),
    new Gradient.ColorFrame(1, Color.Red)
);

Notes

  • Uses SceneLineObject for efficient line rendering
  • Default material is materials/default/default_line.vmat
  • Light uses quadratic attenuation for falloff
  • Tracer samples the line at 10 points for smooth rendering
  • Implements ITemporaryEffect for automatic cleanup when finished
Was this helpful?