Minimal Example
The smallest custom variable setup needs three concrete wrapper classes:
Variable<T>for the actual stored variable typeVariableRef<T>for variable references and outputsVariableVar<T>for action parameters that can use either a constant or a variable
Here is the smallest complete setup for a custom type:
using System;
using HutongGames.PlayMaker;
namespace MyNamespace
{
[Serializable]
[DataType(typeof(MyCustomType))]
public class MyCustomVariable : Variable<MyCustomType>
{
}
[Serializable]
[DataType(typeof(MyCustomType))]
public class MyCustomRef : VariableRef<MyCustomType>
{
}
[Serializable]
[DataType(typeof(MyCustomType))]
public class MyCustomVar : VariableVar<MyCustomType>
{
}
}
The [DataType] attribute tells PlayMaker which runtime type each wrapper represents.
Once these classes exist, your type can appear in the Variables Inspector and can be used by custom actions.
Which Wrapper To Use
Each wrapper has a different job:
Variable<T>
Use Variable<T> for the real stored variable type.
This is the type PlayMaker keeps in the FSM or global variable list.
VariableRef<T>
Use VariableRef<T> when the field should reference an existing variable.
This is a good fit for:
- action outputs
- reference-only parameters
- APIs where a constant value does not make sense
VariableVar<T>
Use VariableVar<T> when the field should allow either:
- a constant value entered directly in the action
- a reference to a variable of the same type
This is the most common choice for action inputs.
Using Custom Variables In Actions
After you define the wrapper classes, action fields work the same way as built-in PlayMaker variable types.
For example:
[Tooltip("The value to read or edit.")]
public MyCustomVar Value;
[Tooltip("Store the result here.")]
[WriteOnly]
public MyCustomRef StoreValue;
In the action code, read and write through the Value property:
This keeps the action code consistent with built-in PlayMaker variable patterns.