menu_bookDocumentation
Beams - s&box Rendering Documentation
Beams
Beam effects create animated lines between points - useful for lasers, lightning, energy beams, and trails.
BeamEffect Component
Create beams using the BeamEffect component:
CSHARP
var beam = new GameObject();
var effect = beam.Components.Create<BeamEffect>();
// Set start and end points
effect.StartPosition = gunTipPosition;
effect.EndPosition = hitPosition;
// Configure appearance
effect.Color = Color.Cyan;
effect.Width = 5f;Follow Points
Beams can automatically follow moving objects:
CSHARP
// Set transform references
effect.StartTransform = gunTip;
effect.EndTransform = target;
// Beam updates automatically as transforms moveProperties
- Color — Beam color (can be animated)
- Width — Beam thickness
- Texture — Scrollable texture for energy effects
- Scroll Speed — Animation rate for texture
- LifeTime — How long the beam exists
Use Cases
- Weapon lasers and tracers
- Lightning effects
- Energy weapons
- Teleportation beams
- Grappling hooks
- UI targeting lines
Performance
Beams are lightweight effects that render efficiently. They use the same rendering path as particles.
Combining with Code
CSHARP
// Create a laser that fades out
public void FireLaser( Vector3 start, Vector3 end )
{
var beam = new GameObject();
var effect = beam.Components.Create<BeamEffect>();
effect.StartPosition = start;
effect.EndPosition = end;
effect.Color = Color.Red;
effect.LifeTime = 0.1f; // Disappears after 100ms
}Beams are perfect for real-time visual effects that need to stretch between two points.
Was this helpful?