Skip to content

BaseDebugLogAction

BaseDebugLogAction is an abstract base class for actions that log messages to the Unity Console and, in the editor, the FSM Log.

It provides the shared logging behavior used by actions such as DebugLog and DebugLogVariable.

Core Functionality

The class provides:

Logging Types

Defines an enum Type with three severity levels:

  • Info: Standard informational messages
  • Warning: Warning messages that indicate potential issues
  • Error: Error messages that indicate problems requiring attention

Logging Method

Implements a protected static Log method that handles sending messages to the Unity console with the appropriate severity level.

protected static void Log(Type logType, string message)

This method maps each Type value to the corresponding Unity logging call:

  • Info -> Debug.Log
  • Warning -> Debug.LogWarning
  • Error -> Debug.LogError

Summary Helper

The base class also provides a helper for generating consistent action summaries:

protected static string GetLogSummary(Type logType, string summary)

This prefixes the summary with the correct label for the selected log type, such as:

  • Log
  • Log Warning
  • Log Error

FSM Logging

Implements a protected FsmLog method to send messages to the FSM Log with the appropriate severity level.

protected void FsmLog(Type logType, string message)

This is only active in the Unity Editor.

At runtime builds, the method is excluded with Conditional("UNITY_EDITOR").

This lets logging actions write useful debugging information to the editor FSM log without affecting player builds.

Typical Pattern

Actions that inherit from BaseDebugLogAction usually follow this pattern:

  1. Build the output string in Execute()
  2. Call Log(logType, output) to write to the Unity Console
  3. Call FsmLog(logType, output) to also write to the FSM Log in the editor
  4. Use GetLogSummary(...) in GetSummary() for a consistent action label

Example

DebugLog is a typical example:

using UnityEngine;
using JetBrains.Annotations;

namespace HutongGames.PlayMaker.Actions
{
    [System.Serializable]
    [PublicAPI]
    [ActionCategory(Category.Debug)]
    [ActionDescription("Print a message to the Unity Console and FSM Log.")]
    public class DebugLog : BaseDebugLogAction
    {
        [Tooltip("Message Type.")] 
        public Type LogType;

        [Delayed, HideLabel, OptionalField, Multiline(5), HasVariableNames]
        [DefaultValue("")]
        [Tooltip("Text to log to the Unity Console.")]
        public StringVar Text;

        public override void Execute()
        {
            var output = GetOutput();

            Log(LogType, output);
            FsmLog(LogType, output);
        }

        private string GetOutput() => Text.IsVariable 
            ? DebugUtility.GetDebugString(Text.Variable) 
            : DebugLogTextFormatter.Format(Text.Value, Fsm?.Variables);

        public override string GetSummary() => GetLogSummary(LogType, "{Text}");
    }
}

With this setup, the base class handles the common logging behavior and summary formatting, while the derived action only needs to define what text should be logged.

When To Use It

Use BaseDebugLogAction when your action:

  • writes messages to the Unity Console
  • supports different log severities
  • should also write to the FSM Log in the editor
  • needs a consistent summary format for log actions

If the action is not actually logging anything, another base class is usually a better fit.