Skip to content

Control the flashlight

Drive the player’s flashlight from your mod. Every call does nothing when TightBeam is not installed, so you need no hard dependency.

You need: a MelonLoader mod project.

  1. Copy the shim file (TightBeam.cs, namespace TightBeam.Api) into your project. It has no Unity references and compiles into your DLL. You can reference TightBeam.Api.dll instead.

  2. Call the API from the Unity main thread.

    using TightBeam.Api;
    Beam.Blink(3); // blink 3 times
    Beam.Flicker(0.35f, 6f, 11f); // 35% depth, 6 s, about 11 Hz
    Beam.SetColorHex("#ff3030"); // tint the beam red
  3. To hold a value while the player is in a zone, use a scoped override. Give it a stable, unique owner id (your mod name).

    using (var ov = Beam.BeginOverride("MyMod"))
    {
    ov.SetIntensity(1f).SetSpotAngle(28f);
    // ... while the player is in the zone ...
    } // Dispose() releases the override
  4. Always release the override. Then the beam returns to the player’s own settings.

Calls made before TightBeam is ready are queued and run when it binds. Load order does not matter.

Install TightBeam, load a save and run your code. The beam blinks, flickers or changes colour. Without TightBeam, nothing happens and no error appears.

MemberMeaning
bool Beam.Availabletrue when TightBeam is installed and bound. You rarely need it.
bool Beam.IsOnThe flashlight is on.
float Beam.Intensity / Range / SpotAngleCurrent composited values.
Beam.GetColor(out r, out g, out b, out a)Current colour, floats 0..1.
event Action<bool> Beam.OnToggledFires when the flashlight goes on or off, by key or by any mod.
MethodWhat it does
Beam.TurnOn() / TurnOff() / Toggle() / SetOn(bool)Switch the game’s own flashlight.
Beam.SetIntensity(float)Base brightness, clamped to the configured Min/Max.
Beam.SetRange(float meters)Pin the range until the player scrolls focus.
Beam.SetSpotAngle(float degrees)Pin the cone angle until the player scrolls focus.
Beam.SetColor(float r, float g, float b, float a = 1)Set the colour, floats 0..1.
Beam.SetColorHex(string hex)Set the colour from #RRGGBB or #RRGGBBAA.
MethodWhat it does
Beam.Blink(int times, float intervalSeconds = 0.12f)Blink N times.
Beam.Flicker(float strength01, float durationSeconds, float frequencyHz = 14f)Smooth noise flicker.
Beam.StopFlicker()Stop the flicker.
Beam.Pulse(float amplitude01, float periodSeconds, float durationSeconds)Sine pulse of the brightness. Use float.PositiveInfinity to pulse until stopped.
Beam.StopPulse()Stop the pulse.
Beam.SetTemporaryIntensity(float value, float seconds, float fadeSeconds = 0.25f)Brightness override that restores after seconds.
Beam.SetTemporaryColor(float r, float g, float b, float seconds, float a = 1, float fadeSeconds = 0.25f)Colour override that restores after seconds.

Beam.BeginOverride(string ownerId) returns an OverrideHandle. Overrides from several mods stack. For each field, the newest non-null value wins.

OverrideHandle memberWhat it does
.SetIntensity(float) / .SetRange(float) / .SetSpotAngle(float) / .SetColor(r, g, b, a = 1)Hold that field. Chainable.
.ClearIntensity() / .ClearRange() / .ClearSpotAngle() / .ClearColor()Release one field.
.Dispose()Release the whole override.

Needs ABI 2. Players are identified by SteamID64, the same value as Player.PlayerCode.

MemberWhat it gives you
Beam.AbiVersion0 without TightBeam, 1 for a local-only host, 2 when the members below work.
Beam.IsMultiplayertrue with at least one other player.
Beam.LocalSteamIdYour own id, or 0 if not yet known.
Beam.RemoteIdsEvery tracked remote player. Never null.
Beam.RemoteHasTightBeam(id)false means the values you read are local defaults, not their settings.
Beam.TryGetRemote(id, out RemoteBeamState)Their drawn beam: IsOn, Intensity, Range, SpotAngle, R/G/B/A.
Beam.TryGetRemotePose(id, out px, py, pz, fx, fy, fz)Beam start and direction. false when the beam is not drawn.
Beam.IsRemoteRendered(id)The beam is on screen, not culled by distance or the beam cap.
Beam.OnRemoteToggledAction<ulong, bool>. Fires when another player’s beam goes on or off.
foreach (var id in Beam.RemoteIds)
{
if (!Beam.TryGetRemotePose(id, out var px, out var py, out var pz,
out var fx, out var fy, out var fz)) continue;
// compare the beam direction with the vector from the beam to the player
}

There are no remote setters. Each player owns their own beam. To change what others see, change your local beam: an override from BeginOverride replicates by itself.

  • Call every method on the Unity main thread.
  • Use a stable, unique ownerId and always release it.
  • The API is additive-only (current ABI 2). An older shim works with a newer host. A newer shim reports nothing for members an older host lacks.