AnimationParameters Class
A simple named-parameter store designed as a companion to AnimationStateMachine transition conditions. Removes the need to manually manage boolean flag resets in lambdas.
public sealed class AnimationParameters
Inheritance System.Object → AnimationParameters
Remarks¶
Four value types are supported:
- Bool — Latching boolean, stays set until explicitly cleared.
- Float — Continuous float value, e.g. speed or blend weight.
- Int — Integer value, e.g. combo counter or health tier.
- Trigger — Fire-once boolean: GetTrigger(string) returns true exactly once after
SetTrigger(string) is called, then resets automatically. Safe to poll every frame
in a transition condition lambda — only the first frame that reads it will see true.
Typical usage:
var p = new AnimationParameters();
sm.AddTransition("idle", "walk", () => p.GetFloat("speed") > 0.1f);
sm.AddTransition("walk", "attack", () => p.GetTrigger("attackPressed"));
sm.AddTransition("idle", "hurt", () => p.GetInt("health") <= 0);
// Each frame:
p.SetFloat("speed", velocity.Length());
if (inputAttack) p.SetTrigger("attackPressed");
Warning:GetTrigger(string) consumes the trigger immediately upon reading it.
Do not combine it with other conditions using && or ||, as the trigger
will be consumed even if the other operand short-circuits the result. Use
IsTriggerArmed(string) as the condition guard and call GetTrigger(string) only
when you intend to consume it.
| Methods | |
|---|---|
| CaptureSnapshot() | Captures an immutable snapshot of all current parameter values (bools, floats, ints, and armed triggers). Use RestoreSnapshot(AnimationParametersSnapshot) to revert to this state atomically. |
| ClearBools() | Clears all bool parameters. |
| ClearFloats() | Clears all float parameters. |
| ClearInts() | Clears all int parameters. |
| ClearTriggers() | Clears all armed triggers. |
| GetArmedTriggerNames() | Returns all currently armed trigger names. |
| GetBool(string) | Gets a boolean parameter. Returns false if the parameter has never been set. |
| GetBoolNames() | Returns all bool parameter names that have been set. |
| GetFloat(string) | Gets a float parameter. Returns 0f if the parameter has never been set. |
| GetFloatNames() | Returns all float parameter names that have been set. |
| GetInt(string) | Gets an integer parameter. Returns 0 if the parameter has never been set. |
| GetIntNames() | Returns all int parameter names that have been set. |
| GetTrigger(string) | Reads and consumes a trigger. Returns true exactly once after SetTrigger(string) was called, then resets to false automatically. |
| HasBool(string) | Returns true if a bool parameter with the given name has been explicitly set. |
| HasFloat(string) | Returns true if a float parameter with the given name has been explicitly set. |
| HasInt(string) | Returns true if an int parameter with the given name has been explicitly set. |
| HasTrigger(string) | Returns true if a trigger with the given name has been explicitly set. Equivalent to IsTriggerArmed(string); provided for naming consistency with HasBool(string), HasFloat(string), and HasInt(string). |
| IsTriggerArmed(string) | Returns true if the named trigger is currently armed (set but not yet consumed). Does not consume the trigger. |
| RemoveBool(string) | Removes a bool parameter entirely. Returns true if it existed. After removal, HasBool(string) returns false and GetBool(string) returns the default value false. |
| RemoveFloat(string) | Removes a float parameter entirely. Returns true if it existed. After removal, HasFloat(string) returns false and GetFloat(string) returns the default value 0f. |
| RemoveInt(string) | Removes an int parameter entirely. Returns true if it existed. After removal, HasInt(string) returns false and GetInt(string) returns the default value 0. |
| Reset() | Clears all bools, floats, ints, and triggers. |
| ResetTrigger(string) | Disarms a trigger without consuming it via GetTrigger(string). No-op if the trigger is not currently armed. |
| RestoreSnapshot(AnimationParametersSnapshot) | Restores all parameter values from a previously captured snapshot, replacing all current values atomically. |
| SetBool(string, bool) | Sets a boolean parameter. |
| SetFloat(string, float) | Sets a float parameter. |
| SetInt(string, int) | Sets an integer parameter. |
| SetTrigger(string) | Arms a trigger. The next call to GetTrigger(string) for this name will return true and immediately disarm it. Safe to call multiple times before it is read — it remains armed until consumed. |