BaseAction
All actions inherit from HutongGames.PlayMaker.BaseAction.
A minimal custom action looks like this:
using System;
using HutongGames.PlayMaker;
using UnityEngine;
namespace MyNameSpace
{
[Serializable]
[ActionCategory("MyCategory")]
[ActionDescription("Description shown in help...")]
public class MyCustomAction : BaseAction
{
[Tooltip("A float variable.")]
[SerializeField] private StringVar _name;
// Optional: Check that required parameters have values:
public override bool CanExecute() => CheckParameters(_name);
public override void Execute()
{
Debug.Log($"Hello {_name.Value}!");
}
public override string GetSummary() => "Say hello {_name}";
}
}
It is good practice to use one cs file per action.
Namespace
Your actions should use your namespace.
This is particularly important if you copy an existing action and modify it. Replace the HutongGames namespace with your own to avoid conflicts with PlayMaker updates.
Attributes
Every action should have ActionCategory and ActionDescription attributes.
Every parameter should have a Tooltip attribute.
See attributes for other ways to configure the action.
OnStateEnter
Called when the state is enterered. Called on all enabled actions before any actions start running. Use this to capture information before any action runs.
For example the TransformSmoothPosition uses this to get the initial position of the transform before any actions modify it. Then when the TransformSmoothPosition action runs it can smooth changes made to the initial position.
Note: This method is not used very often, but is sometimes the best way to solve a difficult problem.
OnStart
Called when the action starts running. Use this method to run code that needs to run once before executing the action.
OnStop
Called when the action stops, either because the state has exited or the action has finished. Only called if OnStart was called.
OnStateExit
Called when the state exits. Use this to cleanup any work done in OnStateEnter.
Execute
Most actions use the Execute() method to do their work. The update mode determines when Execute is called.
You can check the CurrentUpdateMode property while inside Execute.
Runtime Validation:
Actions should validate runtime conditions (e.g., targets that may not exist yet) and exit early if they are not currently valid.
For every-frame actions, this allows the action to “wait” until the situation becomes valid on a later update.
In these cases you generally do not call Finish() - the action will receive another Execute call on the next update if its update mode requires it.
Non–every-frame actions will run once and finish naturally after Execute returns.
CanExecute
The CanExecute() method should return false if the action is not configured correctly.
This prevents the action from starting and logs an error automatically.
Use the CheckParameters helper method to ensure required fields are assigned:
You should not check optional fields.
Progress
Actions can show a progress bar in the Action Editor.
To update the progress bar set the Progress property to a value between 0 and 1.
GetSummary
Override GetSummary to return a template for the natural language summary for the action:
The field name should match the serialized field name exactly.
HasDebugInfo
Property that indicates if the action has a GetDebugInfo method. Overwrite this and return true if the action implements GetDebugInfo.
This is an editor only property, so should be in an #if UNITY_EDITOR block.
GetDebugInfo
Returns a string that is displayed at runtime. Use this to display extra information that helps debug the action.
This is an editor only property, so should be in an #if UNITY_EDITOR block.