Skip to content

BaseTweenAction

BaseTweenAction is an abstract base class for actions that animate a value over time using PlayMaker's tween system.

It provides the shared timing, easing, looping, and event behavior used by tween actions such as TweenColor, TweenQuaternion, and TweenLightIntensity.

Core Functionality

The class provides:

Update Mode Setup

BaseTweenAction configures tween actions to run every frame:

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

Easing

All tween actions include a TweenEasingBlock:

public TweenEasingBlock Easing;

This controls how the tween progresses over time, for example linear, ease-in, or ease-out motion.

Update Settings

All tween actions include a TweenUpdateBlock:

public TweenUpdateBlock TweenUpdate;

This controls how the tween advances, such as time-based or speed-based updates.

Loop Settings

Tween actions can optionally include a TweenLoopBlock:

public TweenLoopBlock Loop;
public LoopMode LoopMode => Loop?.LoopMode ?? LoopMode.None;
public int LoopCount { get; set; }

This allows tween actions to repeat without every tween action having to implement its own loop logic.

Tween Events

Tween actions can optionally include a TweenEventsBlock:

public TweenEventsBlock Events;

When the tween reaches the end and is not looping, BaseTweenAction sends the configured finished event and then finishes the action.

Distance Helper

The base class exposes a Distance property:

public float Distance { get; protected set; } = -1;

This gives tween actions a shared way to estimate the length of the tween. It is mainly useful when converting a speed-based tween into a duration.

Validation

BaseTweenAction validates the common tween blocks:

public override bool CanExecute() => Easing.IsValid && TweenUpdate.IsValid;

Derived actions typically extend this by checking their own target values as well.

Execution Flow

In Execute(), the base class:

  1. Advances the tween using TweenUpdate.Execute()
  2. Stores the current Progress
  3. Checks whether the tween has reached the end
  4. Sends the finished event and calls Finish() if the tween is not looping

Derived actions usually call base.Execute() first, then apply the tweened value using the current Progress.

Summary Helper

BaseTweenAction also appends the common tween settings to the action summary:

public override string GetSummary()

This includes the update settings, easing, optional loop settings, and optional tween events.

Example

TweenColor is a typical example:

using System;
using JetBrains.Annotations;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [System.Serializable]
    [PublicAPI]
    [ActionCategory(Category.Tween)]
    [ActionDescription("Tween a Color variable.")]
    public class TweenColor : BaseTweenAction
    {
        [Tooltip("The color variable to tween.")]
        [SerializeField, WriteOnly]
        private ColorRef _color;

        [Tooltip("Tween from or to the given value.")]
        [SerializeField]
        private TweenDirection _direction;

        [Tooltip("The color to tween to.")]
        [SerializeField]
        private ColorVar _value;

        [NonSerialized] private Color _fromColor;
        [NonSerialized] private Color _toColor;

        public override bool CanExecute() => CheckParameters(_color, _value) && base.CanExecute();

        public override void OnStart()
        {
            base.OnStart();

            if (_direction == TweenDirection.To)
            {
                _fromColor = _color.Value;
                _toColor = _value.Value;
            }
            else
            {
                _fromColor = _value.Value;
                _toColor = _color.Value;
            }

            Distance = Vector4.Distance(_fromColor, _toColor);
        }

        public override void Execute()
        {
            base.Execute();
            _color.Value = Color.Lerp(_fromColor, _toColor, Easing.Evaluate(Progress));
        }
    }
}

With this setup, the base class handles tween progress, looping, and completion, while the derived action only needs to define the start and end values and apply the tweened result.