Modifiers extension
August 17, 2025 · View on GitHub
Easily make flexible parameters for your characters, items, abilities, buffs in Unity.
Use cases
For example, your game character has various parameters, such as move speed, max health and others.
You may want to modify these parameters dynamically — for example, using potion buffs to increase character parameters, enemy attack debuffs to decrease them. These effects should also stack and combine seamlessly.
This extension provides an easy way to implement such a system.
How it works
Instead of using basic variables, the system replaces them with a Modifier Param (name subject to change). This can represent any parameter — max health, damage, movement speed, or any other value. These parameters can be grouped into a Modifier, which defines the stats of an object — such as a character, buff, item, or anything else.
There is a Modifier class, which contains of user-defined parameter types, you can flexible change it. Every buff or other thing has its own Modifier. For Unity, there is a UnityModifier class, which inherits from ScriptableObject — each modifier exists as a standalone asset in your project, making it easy to create and manage.
There also Modifiable class, which you can add for your character/weapon/etc. It contains basic params of this object (something like default Modifier), and can be affected by adding/removing other modifiers from code. Modifable is a MonoBehaviour, it can be added to your objects by drag n drop.
You can access Modifiable parameters with a simple API and get values of your params — it automatically will summarize all modifiers, added to this object, and return final value, actual for this param.
All these parameters can be edited or added/removed at all without any code and project recompile.
Modifiers work example:
- Character move speed without modifiers is 3.
- Some speed up buff adds extra 2 speed.
- Also there is some debuff which really slows down character, its speed value -4.
- So, final value (returned by the API) of character speed is 1 (3 + 2 + (-4)).
Why just not to use OOP and variables
Modifiers extension allows you to:
- Unified serialization.
- Ready-made Sum and Subtract operations for the params.
- Easily get values from GameObject, there is no need to use GetComponent or something other.
- Easy to add new or remove old ones with minimum refactoring amount, which can be easily done with modern IDEs.
- Easily move some of your gameplay systems between projects, since Modifiers allow your code to not depend on other game classes (check the example for more info).
It is works nice with MonoBehaviour approach, in other cases you may prefer your own implementation. Also, there are still some limitations — for example, if your game have stats for different types of objects (items, characters, etc), it is not very comfy to work with them in one Enum.
How to install
First of all, you need install dependencies:
Next, you can install this package by using Package Manager: https://github.com/OlegDzhuraev/Modifiers.git
Alternative install: download repo as source code, unpack to your project. Also, you can check Releases for unitypackage.
Quick start
Setup steps
- On startup window should appear with request to create Unity Modifiers Settings. Also you can manually create it by Right click context menu in the Project Window (or take it from the Example folder).
- Add some values into its Supported Params list.
- To use it from code with more comfort, you need to generate constants (all examples use generated constants, so, better to do it). It can be found in the Top Menu -> Tools -> Insane One Modifiers -> Common... -> Generate constsants button. It will generate the ModType static class with a list of constants, similar to your strings list in the Settings asset. It is not necessary to generate it.
Adding a new modifier types
Insert them to the Supported Params list of the Unity Modifiers Settings asset. Example values can be removed.
Don't forget about constants generation, if you're planning to use them.
How to rename already exist modifiers types
It can look a kinda tricky comparing string type names to, for example, Enum usage, but it is easy with modern IDE. You need to:
- Replace string type name in all assets (Prefabs and SO), using your IDE. Replace all the "OldName" to the "NewName". Note that quotes means strings, so include it in your replace request.
- (only if you're using generated constants) rename the OldName constant to the NewName using your IDE. It will replace all code usages.
- (fully optional, also only if you're using generated constants) Generate new constants to approve that you renamed all correct.
How to create a new modifier?
Right click in the Project window -> Modifiers -> New modifier.
Next, you're need to add required params to the list in this modifier. It can be Health, Damage, etc.
How to create buff?
Buffs are modifiers with a lifetime and stacks amount parameter. It is just simplifies creation of this functionality.
Right click in the Project window -> Modifiers -> New buff.
Setup buff parameters, add buff modifiers.
You can create your own buff class (derived from Buff) and add there your info, it can be icon, text id or something other.
Code usage
In order to use this package, you need to add scripting define symbol INSANEONE_UNITY_MODIFIERS_EXTENSION to the Project Settings.
It enables extension methods for GameObject class and ModifiableBehaviour class, used as shortcut to modifiers methods.
You also can skip this and use package without this define, but it not so handy and examples will not work.
Initialization
In order to make all things work, you need to have some initialization MonoBehaviour script. It can look like this:
using UnityEngine;
using InsaneOne.Modifiers;
public class ModifiersInitialization : MonoBehaviour
{
[SerializeField] UnityModifiersSettings settings;
void Start()
{
settings.SetAsActive(); // loads this instance of UnityModifiersSettings into the game as active config
}
}
You need to do this before using in runtime (play mode) any features of package. You can place this init in your own game initialization script.
Adding and removing modifiers
This is one of the most common actions. You will add and remove stats for your characters and other objects regularly.
using UnityEngine;
using InsaneOne.Modifiers;
// <...>
[SerializeField] Modifier modifier;
void Start()
{
// This and below code uses custom extensions methods
// Add
gameObject.AddModifier(modifier);
// Remove (note that if you instance modifier, by remove method you will be able to remove only modifiers, same to instance, not the original one).
gameObject.RemoveModifier(modifier);
}
Get actual value
This is another most common action. To handle any values, you need to get them somehow. This example shows, how it's done in this extension.
// Getting value of Max Health param
gameObject.GetModifierValue(ModType.MaxHealth);
Tags
If you need to tag object and check if object have some tags, you can use these methods. Tags are just simple numbers like other stats, but these methods allows to work with them easily and make code more short.
gameObject.AddTag(ModType.TagA);
if (gameObject.HasTag(ModType.TagA))
{
// do something
}
// checking for multiple tags, AND condition example
if (gameObject.HasAllTags(ModType.TagA, ModType.TagB))
{
// do something if there all on the object
}
// OR condition example
if (gameObject.HasAnyTags(ModType.TagA, ModType.TagB))
{
// do something if there at least one tag of the listed above.
}
Make Filter and get results
// making filter which will filter all objects with team 1
Filter filter;
void Start()
{
filter = Filter.Make(ModType.Team, 1);
}
void Update()
{
var results = filter.GetResults();
foreach (GameObject teamedGo in results)
{
// you can do something with result objects
}
}
Other usage examples can be found in the Example package.
Example
You can find it in the Example package, there is a sample scene. It shows simple character with Max Health, Regeneration and Defense parameters. Also, there is a "damager" which have Damage and Critical Chance parameters. Damage will be applied to the character on left mouse button click. Critical chance will be used to make x2 damage, if random value hits the chance.
Showcase
Battleproofed in the Echo Storm game.
License
Apache 2.0