Skip to content

BaseFadeAction

BaseFadeAction is an abstract base class for actions that animate a target over time using a normalized fade value from 0 to 1.

It provides the common timing and completion logic used by fade-style effects such as FadeInLight, FadeOutLight, and FadeOutCanvasGroup.

Core Functionality

The class provides:

Fade Timing

The Duration field controls how long the fade takes in seconds.

The fade starts at progress 0, advances every frame, and ends at progress 1.

Realtime Option

The UseRealtime field lets the action ignore Unity time scale:

  • false: Uses Time.deltaTime
  • true: Uses Time.unscaledDeltaTime

This is useful for fades that should continue while the game is paused or slowed down.

Progress Output

The optional _Progress output stores the normalized fade progress from 0 to 1.

You can use this to synchronize other effects with the fade.

Finished Event

The optional FinishedEvent is sent when the fade reaches the end.

After sending the event, the action finishes automatically.

Update Mode Setup

BaseFadeAction sets the appropriate update mode for a time-based action:

public override UpdateMode DefaultUpdateMode => UpdateMode.UpdateEveryFrame;
public override UpdateMode RequiredUpdateModes => UpdateMode.EveryFrame;
public override bool CanFinish => true;

Required Overrides

Inheritors must implement:

protected abstract void Apply(float t);

t is the normalized progress of the fade from 0 to 1.

Derived actions usually use t with Mathf.Lerp to animate a target value.

Summary Helpers

The base class also provides helper methods for action summaries:

protected string GetFadeInSummary(string target = "Target")
protected string GetFadeOutSummary(string target = "Target")

These make it easy for inheritors to return consistent summaries.

Example

FadeInLight is a simple example:

using System;
using JetBrains.Annotations;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [Serializable, PublicAPI]
    [ActionCategory(Category.Fade)]
    [ActionDescription("Fades a Light in by animating its intensity from 0 to its starting intensity.")]
    public class FadeInLight : BaseFadeAction
    {
        [Tooltip("The Light to fade in.")]
        public LightVar Light;

        private float _toIntensity;

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

        public override void OnStart()
        {
            _toIntensity = Light.Value.intensity;

            // Ensure it's visible during fade.
            Light.Value.enabled = true;
            Light.Value.intensity = 0f;

            base.OnStart();
        }

        protected override void Apply(float t)
        {
            Light.Value.intensity = Mathf.Lerp(0f, _toIntensity, t);
        }

        public override string GetSummary() => GetFadeInSummary(nameof(Light));
    }
}

With this setup, the base class handles timing, progress, completion, and finishing the action. The derived action only needs to define how the target changes as the fade progresses.