codeAPI Reference

Sandbox.Light

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Sandbox.Light

Illuminates the scene.

Overview

Light component adds dynamic lighting to GameObjects. Supports point, spot, and directional lights.

Setup

CSHARP
var light = gameObject.Components.Create<Light>();
light.LightType = LightType.Point;

Light Types

TypeDescription
PointOmni-directional (bulb, torch)
SpotCone-shaped (flashlight, streetlight)

Properties

PropertyDescription
LightTypePoint or Spot
ColorLight color (white, warm, etc.)
BrightnessIntensity
RangeFalloff distance
AttenuationFalloff curve

Spot Light

CSHARP
var spot = gameObject.Components.Create<Light>();
spot.LightType = LightType.Spot;
spot.InnerConeAngle = 30f;
spot.OuterConeAngle = 45f;
spot.Color = Color.White;
spot.Brightness = 1000f;
spot.Range = 1000f;

Point Light

CSHARP
var point = gameObject.Components.Create<Light>();
point.LightType = LightType.Point;
point.Color = new Color(1, 0.8f, 0.6f); // Warm
point.Brightness = 500f;
point.Range = 500f;

Shadow

CSHARP
light.Shadows = ShadowType.Cascade;
// or
light.Shadows = ShadowType.Single;

Animated

CSHARP
// Flickering torch
protected override void OnUpdate()
{
    light.Brightness = 500f + Random.Shared.Float(-50, 50);
}

Performance

  • Limit overlapping lights
  • Use lower brightness for distant lights
  • Disable shadows for small/unimportant lights
  • Bake static lighting when possible
Was this helpful?