Skip to content

BaseFxDriver

BaseFxDriver is an abstract base class for actions that drive visual effects from a changing input value.

It provides shared input mapping logic for actions such as FxDriverLight and FxDriverParticleSystem.

Core Functionality

The class provides:

Input Mapping

BaseFxDriver maps a raw input value into a normalized range from 0 to 1.

This makes it easy to drive an effect from values such as:

  • speed
  • thrust
  • health
  • charge

Input Fields

The base class defines these shared input settings:

  • _input: The raw value that drives the effect.
  • _inputMin: The input value that maps to 0.
  • _inputMax: The input value that maps to 1.
  • _clampInput: If true, clamps the input to the min/max range before mapping.

Safe Range Handling

The input mapping is safe when:

  • InputMin and InputMax are swapped
  • the range is zero-length

If the min and max values are the same, the normalized result is 0.

Helper Methods

Inheritors can use these helpers:

protected float GetInput01()
protected float RemapInput(float outMin, float outMax)

GetInput01() returns the normalized input value from 0 to 1.

RemapInput() converts that normalized value into any output range you want.

Validation

The base class already checks that _input is assigned:

public override bool CanExecute() => CheckParameters(_input);

Derived actions usually extend this by checking their own target component as well.

Example

FxDriverLight is a simple example:

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [Serializable]
    [ActionCategory(Category.FxDriver)]
    [ActionDescription(
        "Drives a Light from an input value.\n" +
        "Maps the input into 0–1 using InputMin/Max, then scales intensity\n" +
        "and optionally applies a color gradient with HDR boosting.")]
    public sealed class FxDriverLight : BaseFxDriver
    {
        public override UpdateMode DefaultUpdateMode => UpdateMode.UpdateEveryFrame;
        public override UpdateMode RequiredUpdateModes => UpdateMode.EveryFrame;

        [Tooltip("The Light to drive.")]
        [SerializeField]
        private LightVar _light;

        [Tooltip("Light intensity at input 0 (mapped to 0).")]
        [SerializeField, DefaultValue(0f)]
        private FloatVar _minIntensity;

        [Tooltip("Light intensity at input 1 (mapped to 1).")]
        [SerializeField, DefaultValue(2f)]
        private FloatVar _maxIntensity;

        public override bool CanExecute() =>
            base.CanExecute() && CheckParameters(_light);

        public override void Execute()
        {
            var light = _light.Value;
            if (light == null)
                return;

            var t = Mathf.Clamp01(GetInput01());
            light.intensity = Mathf.Lerp(_minIntensity.Value, _maxIntensity.Value, t);
        }
    }
}

With this setup, the base class handles the input normalization and the derived action only needs to decide how that normalized value affects the target effect.