Update Manager
At runtime, all PlayMaker FSMs are updated by the PlayMakerUpdate singleton.
This approach provides the performance improvements discussed in this Unity blog post.
Most of the API is exposed as static methods on PlayMakerUpdate.
Active FSMs
To get all active FSMs call:
This will return all FSMs currently registered with the UpdateManager.
Upgrade Tip
This is similar to Fsm.FsmList in PlayMaker 1.
Current Update
If you need to know which managed object is currently being updated, use:
This is exposed through the IUpdateManager interface:
This is mainly useful for debugging and tooling.
Registering Updates
PlayMakerUpdate can call any object that implements IManagedUpdate.
You can register for updates in a few different ways depending on how much control you need.
Register Based on UpdateMode
Register for specific update callbacks:
PlayMakerUpdate.Register(UpdateMode.Update, myUpdate);
PlayMakerUpdate.Register(UpdateMode.FixedUpdate | UpdateMode.LateUpdate, myUpdate);
The matching unregister method is:
Register All Update Callbacks
If you want all managed update callbacks, use:
This registers:
UpdateFixedUpdateLateUpdateOnAnimatorMove
To remove them again:
Register Based on an FSM
If your object implements IHasFsm, you can let PlayMaker register the update modes used by that FSM:
This is useful when your managed object is associated with an FSM and should follow that FSM's configured update modes.
Individual Registration Methods
If you want explicit control over each callback, these methods are also available:
PlayMakerUpdate.RegisterUpdate(myUpdate);
PlayMakerUpdate.RegisterFixedUpdate(myUpdate);
PlayMakerUpdate.RegisterLateUpdate(myUpdate);
PlayMakerUpdate.RegisterOnAnimatorMoveUpdate(myUpdate);
And the matching unregister methods:
PlayMakerUpdate.UnregisterUpdate(myUpdate);
PlayMakerUpdate.UnregisterFixedUpdate(myUpdate);
PlayMakerUpdate.UnregisterLateUpdate(myUpdate);
PlayMakerUpdate.UnregisterOnAnimatorMoveUpdate(myUpdate);
Finishing Updates
To stop receiving updates after the current update cycle, use one of the Finish methods:
PlayMakerUpdate.Finish(myUpdate);
PlayMakerUpdate.Finish(UpdateMode.Update, myUpdate);
PlayMakerUpdate.FinishUpdate(myUpdate);
This is useful when an IManagedUpdate should remove itself safely while updates are being processed.
IManagedUpdate
You can register your own scripts with the UpdateManager by implementing IManagedUpdate and registering for the updates you need.
public interface IManagedUpdate
{
void OnUpdate();
void OnFixedUpdate();
void OnAnimatorMoveUpdate();
void OnLateUpdate();
string DebugLabel { get; }
}
Example:
using HutongGames;
using HutongGames.PlayMaker;
using UnityEngine;
public class ManagedExample : MonoBehaviour, IManagedUpdate
{
public string DebugLabel => nameof(ManagedExample);
private void OnEnable()
{
PlayMakerUpdate.Register(UpdateMode.Update, this);
}
private void OnDisable()
{
PlayMakerUpdate.Unregister(UpdateMode.Update, this);
}
public void OnUpdate()
{
Debug.Log("Managed update");
}
public void OnFixedUpdate() { }
public void OnAnimatorMoveUpdate() { }
public void OnLateUpdate() { }
}
Application Shutdown
These properties can be useful when debugging shutdown issues:
bool PlayMakerUpdate.AppIsQuitting
float PlayMakerUpdate.AppQuitTime
string PlayMakerUpdate.AppQuitTimeCode
AppIsQuitting is especially useful because PlayMaker avoids creating or using the singleton while Unity is shutting down.