← MPP-Mainstore › Scripts MPP - Light Drain And Restore Download the documentation (.md)

Version 1.8.1 · updated September 24, 2026

MPP - Light Drain And Restore Script V1.8.1 - Documentation

A theatrical lighting effect for a lamp, a lantern, a crystal or any prop your visitors can pick up. While the object is held, its light slowly dims and a smooth rainbow runs through the light color and the glowing materials. When the object is released, the light comes back to its target intensity and the color returns to white, or stays on the color the visitor "picked" by letting go.

This script is standalone - it does not require any other MPP script to function.

New in V1.8: the light is written only when its value really changes (with the same anti-flicker thresholds as MPP - Day Night), at most 15 times per second, and never while the object rests: the "one write every 50 ms forever" of v1.7 is gone. The Debug Logging switch now works and tells you which light and materials are driven, each grab and release, and the write counts. A wrong setup (no scriptable light, no scriptable mesh, a name filter that matches nothing, no RigidBody) is reported in the script console instead of failing in silence. Settings are grouped by category in the Build panel. V1.8.1 only changes the version number. Your settings are kept when you update: see "Updating from v1.7".


Quick Start

  1. After purchase, the script is in your Inventory in Build mode. Add it to an object that has a light and a glowing material: a lamp, a lantern, a crystal ball.
  2. In the object's properties, make sure the object is grabbable (it needs a physics RigidBody with grab allowed), the light is set Scriptable, and the mesh that carries the glowing material is set Scriptable.
  3. Build and visit. Pick the object up: the light dims slowly and cycles through the rainbow, together with the material tint. Let it go: the light comes back and the color fades to white.

That is all most objects need. The rest of this guide details every option.


How It Works

MomentSettingsWhat happens
Scene startStart/...The light and the tint are set to white (default), or left as they are until the first grab
HeldIntensity/Drain Per Second, Intensity/Min While Held, Rainbow/...The intensity drains, the rainbow runs on the light color and the material tint
EmissiveEmissive/...The emissive intensity of the materials follows the light intensity
ReleasedIntensity/Restore Per Second, Intensity/Target On Release, Release Color/...The intensity comes back; the color returns to white or stays as it was

In the Build panel the settings are grouped by category: Start/, Light/, Intensity/, Emissive/, Material/, Rainbow/, Release Color/ and Debug/.

The intensity scale is the one of the light in the editor, from 0 to 100.


Start

With Force White At Init Off and Start After First Grab On, the object is untouched until the first grab: its editor color and intensity stay exactly as you set them.


Light

The script drives one light of the object, set Scriptable in the editor.

While held, the intensity goes down by Intensity/Drain Per Second units every second, and stops at Intensity/Min While Held (default 0). The default drain of 0.02 per second is very slow: a light at 60 needs 50 minutes to go dark. Set 1 for one minute, 3 for twenty seconds.

After release, the intensity goes back up by Intensity/Restore Per Second units every second (default 2: from 0 to 60 in 30 seconds) until it reaches Intensity/Target On Release (default 60). Once the script runs, this target replaces the intensity set in the editor.

The light is written at most 15 times per second, only when its intensity or color moved enough to be visible, plus one exact write when the value stops moving. At rest, nothing is written.


Rainbow

With Rainbow/Enable On Grab On (default), the light color and the material tint cycle through the hue spectrum while the object is held:


Release Color


Emissive

With Emissive/Sync With Light On (default), the emissive intensity of the driven materials follows the light intensity:

Off: the emissive intensity is never written; only the tint is driven.


Materials

A material that keeps refusing its writes is dropped, with a warning, so the script console is not flooded; the other materials go on. The same rule applies to the light.


Editor Properties Reference (24 total)

Start

PropertyTypeDefaultDescription
Start/Start After First GrabboolOnNothing changes until the first grab
Start/Start From Current IntensityboolOnStart from the light's intensity in the scene; Off = from Target On Release
Start/Force White At InitboolOnLight color and material tint set to white at start

Light and Intensity

PropertyTypeDefaultDescription
Light/Light Name Filterstring(empty)Name of the light to drive; empty or not found = first scriptable light
Intensity/Target On Releasenumber, 0-10060Intensity reached after release
Intensity/Drain Per Secondnumber, 0-1000.02Intensity removed per second while held
Intensity/Restore Per Secondnumber, 0-1002Intensity added per second after release
Intensity/Min While Heldnumber, 0-1000Lowest intensity while held

Emissive

PropertyTypeDefaultDescription
Emissive/Sync With LightboolOnEmissive intensity follows the light
Emissive/Target On Releasenumber, 0-1004Emissive when the light is at Target On Release
Emissive/Min While Heldnumber, 0-1000Emissive when the light intensity is 0
Emissive/Gammanumber, 0.2-30.8Curve between the two; below 1 stays bright longer

Material

PropertyTypeDefaultDescription
Material/Name Filterstring(empty)Empty = every material of the first scriptable mesh; a name = that material on every scriptable mesh
Material/Lerp Secondsnumber, 0-10.01Fade of each material write; 0 = instant
Material/Write Interval Secondsnumber, 0.02-10.2Minimum time between two material writes

Rainbow

PropertyTypeDefaultDescription
Rainbow/Enable On GrabboolOnRainbow on the light color and the tint while held
Rainbow/Hue Speednumber, 0-40.1Hue units per second (0.1 = one cycle every 10 s)
Rainbow/Saturationnumber, 0-110 = greys, 1 = vivid
Rainbow/Value (Brightness)number, 0-11Brightness of the rainbow color (not the light intensity)
Rainbow/Smoothing Secondsnumber, 0-30.8Softness of the color changes; also the tint's return to white

Release Color

PropertyTypeDefaultDescription
Release Color/Return To WhiteboolOnLight color returns to white after release (unless Latch Color)
Release Color/Return Secondsnumber, 0-51Pace of the light's return to white
Release Color/Latch ColorboolOffKeep the color of the moment of release

Debug

PropertyTypeDefaultDescription
Debug/Debug LoggingboolOffWrites the chosen light and materials, each grab and release, and the writes per minute to the script console

Version Notes

VersionWhat changed
v1.0 - v1.6First releases: drain while held, restore on release, rainbow, emissive sync
v1.7Smooth rainbow (temporal smoothing), emissive sync with gamma, color latch on release, start after first grab, throttled material writes. Sold until V1.8.1
V1.8.0Anti-flicker light writes (at most 15 per second, none at rest), working Debug Logging, warnings for a wrong setup, guarded writes (a failing material or light is dropped, the rest goes on), effects following the real elapsed time, name filters searched on every scriptable mesh, settings grouped by category
V1.8.1 (this version)Version number only

Updating from v1.7

v1.7V1.8.1
Start After First Grab, Start From Current Intensity, Force White At InitStart/Start After First Grab, Start From Current Intensity, Force White At Init
Light Name FilterLight/Light Name Filter
Target Intensity On Release, Drain Per Second While Held, Restore Per Second On Release, Min Intensity While HeldIntensity/Target On Release, Drain Per Second, Restore Per Second, Min While Held
Sync Emissive With Light, Emissive Target On Release, Min Emissive While Held, Emissive GammaEmissive/Sync With Light, Target On Release, Min While Held, Gamma
Material Name Filter, Material Lerp Seconds, Material Write Interval SecondsMaterial/Name Filter, Lerp Seconds, Write Interval Seconds
Enable Rainbow On Grab, Rainbow Hue Speed, Rainbow Saturation, Rainbow Value (Light Brightness), Rainbow Smoothing SecondsRainbow/Enable On Grab, Hue Speed, Saturation, Value (Brightness), Smoothing Seconds
Return To White On Release, Color Return Seconds, Latch Color On ReleaseRelease Color/Return To White, Return Seconds, Latch Color
Debug LogDebug/Debug Logging

Recipes

A - The default lantern. Defaults: a slow drain, a 10-second rainbow while held, back to white and full light after release.

B - A color picker. Release Color/Latch Color On: the visitor lets go on the color they like, and the lamp keeps it. The next grab starts the rainbow from that color.

C - A candle that burns out. Intensity/Drain Per Second 1, Intensity/Min While Held 0, Rainbow/Enable On Grab Off: held for a minute, the light goes dark; released, it comes back in 30 seconds.

D - Glow only, no light. An object without a light: only the tint (and the emissive, with a light) is driven. Set Start/Force White At Init Off to start from the material's own tint.

E - Several glowing parts. Put the same material name on the parts that must glow together, on any of the object's scriptable meshes, and write that name in Material/Name Filter.


Troubleshooting

SymptomCheck
Nothing happens when I grab the objectThe object must be grabbable (a physics RigidBody with grab allowed); a warning "No RigidBodyComponent..." is written at start otherwise. With Start/Start After First Grab On, the effect only begins at the first grab
The light does not change, only the glowThe light must be set Scriptable (warning "No scriptable light..." at start), or Light/Light Name Filter names a light that does not exist (warning "matches no scriptable light. Using '...'")
The glow does not change, only the lightThe mesh must be set Scriptable (warning "No scriptable mesh..."), or Material/Name Filter matches nothing (the warning lists the names found), or the material accepts neither Tint nor Emissive Intensity
The light jumps to 60 at startStart/Start From Current Intensity Off starts from Intensity/Target On Release. Turn it On, or set the target to your editor value
The lamp changed color at start although nobody touched itStart/Force White At Init On sets it to white at start. Turn it Off (with Start After First Grab On) to leave the object untouched until the first grab
The rainbow is too fast or too slowRainbow/Hue Speed: 0.1 = one cycle every 10 seconds
The color does not come back to whiteRelease Color/Latch Color On keeps the color; or Return To White is Off
The transitions look steppedRaise Rainbow/Smoothing Seconds, and keep Material/Lerp Seconds close to Material/Write Interval Seconds
I want to know what the script doesTurn Debug/Debug Logging On: the script console shows the light and materials chosen, each grab and release, and once a minute the number of light and material writes

Limits


ItemWhat it adds
Light Switch ScriptTurn lamps on and off with fades, by click, chat command or group. Store: https://www.sansar.com/store/listings/7379d48c-2b6f-45f6-b6f1-205ce95aec1c/light-switch-script
Emissive Color Cycle ScriptA three-color cycle on the glow of your materials, without any interaction. Store: https://www.sansar.com/store/listings/23b8b34f-c12a-47ac-930f-5765b1cbcaf9/emissive-color-cycle-script
Gravity Drift On Grab ScriptMakes the same prop float up like a balloon once released. Store: https://www.sansar.com/store/listings/d74417ad-2b75-41b2-9bd7-7a96cf12eef9/gravity-drift-on-grab-script

MPP - My Pretty Pixels. Light Drain And Restore Script V1.8.1 (script MPP - Light Drain And Restore). Store: https://www.sansar.com/store/listings/95238b17-f553-4656-88b6-6bf10e4070b9/light-drain-and-restore-script

↑