https://github.com/madeyellow/animatorparameters
Free strong-typed Unity's animator parameters
https://github.com/madeyellow/animatorparameters
animator dotnet game-development unity
Last synced: about 2 months ago
JSON representation
Free strong-typed Unity's animator parameters
- Host: GitHub
- URL: https://github.com/madeyellow/animatorparameters
- Owner: madeyellow
- License: mit
- Created: 2025-07-13T14:06:49.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-13T15:30:40.000Z (12 months ago)
- Last Synced: 2025-07-26T00:04:44.509Z (11 months ago)
- Topics: animator, dotnet, game-development, unity
- Language: C#
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# β What is it?
**Tired of animator parameter headaches?** This tiny Unity package eliminates you from:
* π« Manually defining string constants for Animator parameters;
* π« Manual caching hashes with `Animator.StringToHash()`;
* π« Remembering names of Get/Set methods for Animator's parameters;
Instead, enjoy the 3-simple-steps:
* Define a strongly-typed parameter from the package;
* Pass its string name (must match Animator parameter name);
* Use `.Value` to get/set values instantly;
It effectively **hashes & caches parameter name** and **reuses it** automatically to get/set values with maximum performance possible. For you it will be as simple as the following:
```
_isMoving = new BooleanParameter("is_moving", _animator);
_isMoving.Value = true; // Done! π
```
# πΎ Installation
* Open **Unity Package Manager** (Window > Package Manager) OR (Window > Package Management > Package Manager) in **Unity 6**;
* Click "+" β "Add package from git URL";
* Paste this **repo's URL**;
* Hit **Install**;
# π Getting started
## Step 1: Define Parameters
Add the namespace and declare your parameters:
```
using MadeYellow.AnimatorParameter;
private BooleanParameter _isMoving;
private FloatParameter _velocity;
private TriggerParameter _onLand;
```
The package support those types of parameters:
* `BooleanParameter` for **Bool** parameters;
* `IntegerParameter` for **Int** parameters;
* `FloatParameter` for **Float** parameters;
* `TriggerParameter` for triggers (best suited for events, like 'fall', etc.);
*Basically, it's the same types that are supported by Unity's `Animator`.*
## Step 2: Instantiate Parameters
Initialize them in `Awake()` or `Start()` with **name** & **Animator** reference:
```
private void Awake()
{
_animator = GetComponent();
// Create instances of parameters like this
_isMoving = new BooleanParameter("is_moving", _animator);
_velocity = new FloatParameter("velocity", _animator);
_onLand = new TriggerParameter("on_land", _animator);
}
```
There are just two arguments among ANY of the AnimatorParameter:
* `codename` It's just a `string`. It MUST be have same name that you've defined inside Animator controller in Unity Editor. *No need to define constant, just pass a string right into the constructor. Parameter will do the rest for you.*;
* `animator` Well, this is the `Animator` that you want to pass values into;
## Step 3: Use Parameters Effortlessly
Now you might GET or SET values by just calling `.Value` property of your parameter!
```
private void HowToSetValues()
{
// This is how you SET values in the Animator
_isMoving.Value = true; // Pass your BOOL value here
_velocity.Value = 10f; // Pass your FLOAT value here
// When you need to activate trigger - you may easily access it
_onLand.Trigger();
}
private void HowToGetValues()
{
// This is how GET values from the Animator
var isCurrentlyMoving = _isMoving.Value;
}
```
## π― Full Usage Example
```
using MadeYellow.AnimatorParameter;
using UnityEngine;
public class AnimatorParameterExample : MonoBehaviour
{
private Animator _animator;
// STEP 1. Define all the parameters you need once
private BooleanParameter _isMoving;
private FloatParameter _velocity;
private TriggerParameter _onLand;
private void Awake()
{
// STEP 2. Cache Animator
_animator = GetComponent();
// STEP 3. Create instances of parameters (define names right in the constructor, no need to cache them) and pass that animator into them
_isMoving = new BooleanParameter("is_moving", _animator);
_velocity = new FloatParameter("velocity", _animator);
_onLand = new TriggerParameter("on_land", _animator);
}
private void SomeSetMethod()
{
// Now somewhere in your script you may use those parameters to update their values
_isMoving.Value = true; // Pass your value
_velocity.Value = 10f; // Pass your value
// When you need to activate trigger - you may easily access it
_onLand.Trigger();
}
}
```
Also you may fetch current value of parameter FROM Animator by getting value of `.Value` property of your parameter:
```
private void SomeGetMethod()
{
// That will fetch a value of "is_moving" parameter from the animator
var isCurrentlyMoving = _isMoving.Value;
}
```
# β‘ Why Youβll Love It
* π§ **Zero name caching** β Define names once in constructors;
* β‘ **Auto-hashing** β Package uses `Animator.StringToHash()` under the hood;
* π **Clean syntax** β `.Value` for get/set, `.Trigger()` for events;
* π **Performance optimized** β Future plans for value-diff checks;
* π¦ **Tiny & dependency-free** β Minimal footprint;
# πΊοΈ Roadmap
## Planned features
* Add a way to smoothly change `Value` of `FloatParameter` in Animator;
# Want me to add something OR found a bug?
Please add an issue and describe your feature request or bug. I will add a feature if consider it usefull, and for sure will fix bugs, 'cause I'm using that package myself in my games.