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:
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:
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:
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:
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:
Derived actions typically extend this by checking their own target values as well.
Execution Flow
In Execute(), the base class:
- Advances the tween using
TweenUpdate.Execute() - Stores the current
Progress - Checks whether the tween has reached the end
- 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:
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.