Skip to content

Scripting API

Instantiate a new Volumetric Light Beam

To create a new Volumetric Light Beam programmatically, simply add the VLB.VolumetricLightBeamSD or VLB.VolumetricLightBeamHD component to a new GameObject:

var myBeam = new GameObject("MyBeam", typeof(VLB.VolumetricLightBeamSD));

or to an existing one:

GameObject myGAO = ...
var myBeam = myGAO.AddComponent<VLB.VolumetricLightBeamSD>();

Enabling / Disabling

The Volumetric Light Beam enabling/disabling mechanism has been designed the same way Unity handles Lights: using the enabled property.
If you want to turn on/off only the beam from script, you can change the enabled property of the component:

var beam = GetComponent<VLB.VolumetricLightBeamSD>();
beam.enabled = false; // turn off the beam (and the beam only)

If a VolumetricLightBeam component is attached on the same GameObject than a Light, disabling the Light component will not disable the beam (the light and the beam are 2 distinct components).

Additionally you can turn on/off both the light and the beam, by simply set the GameObject active/inactive: gameObject.SetActive(false);


Modify properties at instantiation

You can edit and modify any properties of a Volumetric Light Beam just after instantiating by code. For example, the following code adds a new beam, changes its colors, enables and tweaks the 3D Noise feature on it:

var beam = myGAO.AddComponent<VLB.VolumetricLightBeamSD>();
beam.color = Color.red;
beam.noiseMode = VLB.NoiseMode.WorldSpace;
beam.noiseIntensity = 0.75;
beam.noiseScaleUseGlobal = false;
beam.noiseScaleLocal = 0.6;

Modify properties during playtime (automatically)

If you want to modify the beam's properties via Script during runtime/playtime, or via an Animator or a Timeline, the simpler is to:


Modify properties during playtime (manually)

If for some reasons, you don't want to enable these features, you can also manually call the update function from script after modifying your properties. To do that:

  • call UpdateAfterManualPropertyChange:
var beam = myGAO.GetComponent<VLB.VolumetricLightBeamSD>();
beam.fallOffEnd = Time.time * 0.1f;
beam.color = Color.green;
beam.UpdateAfterManualPropertyChange(); // take the changes into account
  • or call GenerateGeometry if your beam uses a custom mesh (geomMeshType == VLB.MeshType.Custom) and you have changed geomCustomSides and/or geomCustomSegments properties:
var beam = myGAO.GetComponent<VLB.VolumetricLightBeamSD>();
beam.color = Color.blue;
beam.geomMeshType = VLB.MeshType.Custom;
beam.geomCustomSides = 32;
beam.geomCustomSegments = 4;
beam.GenerateGeometry(); // call GenerateGeometry instead of UpdateAfterManualPropertyChange because geomCustomSides and geomCustomSegments has been modified