Skip to content

BaseTrueFalseAction

BaseTrueFalseAction is an abstract base class for actions that perform a test and send True/False events. The result can also be stored in a bool variable.

It provides the shared test, event, summary, and validation behavior used by many Check... actions.

Core Functionality

The class provides:

Check Naming Convention

By convention, actions that send True/False events should use a CheckXXX naming convention.

For example: CheckIsVisible, CheckIsSelected, CheckIsPlaying, etc.

This makes it easier for users to quickly find related Check, Get, and Set actions.

True and False Events

BaseTrueFalseAction defines optional output events for both possible results:

public EventRef TrueEvent;
public EventRef FalseEvent;

When Execute() runs, the action evaluates the test and sends either the true event or the false event.

Store Result

The base class also includes an optional StoreResult output:

public BoolRef StoreResult;

If assigned, the action stores the boolean result of the test in this variable.

This is useful when you want to use the result later without branching immediately with events.

Shared Execute Logic

The base class handles the common execution flow:

  1. Call Test()
  2. Store the result in StoreResult if assigned
  3. Send either TrueEvent or FalseEvent

This means inheritors only need to define the test and the summary text.

Summary Generation

BaseTrueFalseAction provides a default GetSummary() implementation.

It automatically builds a summary based on:

  • the true condition
  • the false condition
  • which events are assigned
  • whether StoreResult is assigned

For example, if no events are assigned but StoreResult is used, the summary becomes:

Check if {TrueSummary} -> {StoreResult}

Built-in Error Check

The base class also provides a default ErrorCheck():

public override string ErrorCheck() => !IsValid ? "Action does not send any events or store the result!" : null;

This helps catch actions that would do nothing because they neither send events nor store the test result.

Required Members

Inheritors must implement:

protected abstract bool Test();
protected abstract string TrueSummary { get; }
protected abstract string FalseSummary { get; }
  • Test() performs the actual check
  • TrueSummary describes the true case
  • FalseSummary describes the false case

The summary strings are used by the base class when generating the action summary.

Typical Pattern

Actions that inherit from BaseTrueFalseAction usually follow this pattern:

  1. Validate inputs in CanExecute()
  2. Implement Test() with the boolean condition
  3. Provide TrueSummary and FalseSummary
  4. Let the base class handle result storage, event sending, summary generation, and error checking

Example

CheckIntEquals is a typical example:

using JetBrains.Annotations;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [PublicAPI]
    [ActionCategory(Category.Logic)]
    [ActionDescription("Check if an integer variable is equal to a given value.")]
    public class CheckIntEquals : BaseTrueFalseAction
    {
        [Tooltip("The integer to check.")]
        public IntegerRef Integer;

        [Tooltip("The value to compare to.")]
        public IntegerVar EqualTo;

        public override bool CanExecute() => CheckParameters(Integer, EqualTo);

        protected override bool Test() => Integer.Value == EqualTo.Value;

        protected override string TrueSummary => "{Integer} == {EqualTo}";
        protected override string FalseSummary => "{Integer} != {EqualTo}";
    }
}

With this setup, the derived action only defines the condition and summary text. The base class handles the common behavior for storing the result, sending events, generating summaries, and checking for invalid setup.

When To Use It

Use BaseTrueFalseAction when your action:

  • evaluates a boolean condition
  • may send different events for true and false results
  • optionally stores the result in a bool variable
  • benefits from a consistent Check... style summary and validation behavior

If the action is not centered on a true/false test, another base class is usually a better fit.