codeAPI Reference
s&box Tracer: Projectile trail renderer
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
- WorldPoint EndPoint - The target point for the tracer to travel to.
Speed
- float DistancePerSecond - How fast the tracer travels. Default 1.0.
- float Length - Length of the tracer tail. Default 100.0.
- float StartDistance - Starting distance from origin. Default 200.0.
Rendering
- Gradient LineColor - Color gradient along the tracer length (white to transparent by default).
- Curve LineWidth - Width curve along the tracer length (2 to 0 by default).
- SceneLineObject.CapStyle StartCap - Cap style at the start of the line.
- SceneLineObject.CapStyle EndCap - Cap style at the end of the line.
- bool Opaque - Whether the tracer is opaque. Default true.
- bool CastShadows - Whether the tracer casts shadows. Default true.
- Material Material - Optional custom material for the tracer.
Light
- bool EnableLight - Whether to enable a dynamic light at the tracer head.
- Gradient LightColor - Light color gradient along the path.
- Curve LightRadius - Light radius curve along the path.
- float LightPosition - Position of the light along the tracer (0-1). Default 0.
Component Interfaces
- Component.ExecuteInEditor - Allows the tracer to render in the editor.
- Component.ITemporaryEffect.IsActive - Returns true while the tracer is still animating.
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?