Effects System Tutorial - Build Your First Buff in 5 Minutes¶
What You'll Build¶
By the end of this tutorial, you'll have a complete working buff system with:
- A "Haste" buff that increases speed by 50%
- Visual particle effects that spawn/despawn with the buff
- A "Stunned" debuff that prevents player movement
- Tags you can query in gameplay code
Time required: 5-10 minutes
Why Use the Effects System?¶
The Old Way:
The New Way:
Result: Designers create hundreds of effects without programmer involvement.
Step 1: Create Your First AttributesComponent (2 minutes)¶
This component will hold the stats that effects can modify.
What's an Attribute?
- Holds a base value (e.g., Speed = 5)
- Tracks modifications from multiple sources
- Calculates final value automatically (Add → Multiply → Override)
- Raises events when value changes
⚠️ Important: Use Attributes for "max" or "rate" values, NOT "current" depleting values!
- ✅ MaxHealth - modified by buffs (good)
- ❌ CurrentHealth - modified by damage/healing from many systems (bad - causes state conflicts)
- ✅ AttackDamage - modified by strength buffs (good)
- ✅ Speed - modified by haste/slow effects (good)
If a value is frequently modified by systems outside the effects system (like health being reduced by damage), use a regular field instead. See the main documentation for details.
Step 2: Add Stats to Your Player (30 seconds)¶
- Open your Player prefab/GameObject
- Add Component →
PlayerStats - Set values in Inspector:
- Speed:
5 - MaxHealth:
100 - AttackDamage:
10 - Defense:
5
That's it! Your player now has modifiable attributes.
Step 3: Create a Haste Effect (2 minutes)¶
3.1 Create the ScriptableObject¶
- In Project window:
Right-click→Create→Wallstop Studios→Unity Helpers→Attribute Effect - Name it:
HasteEffect
3.2 Configure the Effect¶
Select HasteEffect and set these values in Inspector:
Modifications:
- Click "+" to add a modification
- Attribute Name:
Speed(must match field name exactly) - Action:
Multiplication - Value:
1.5(150% of base speed)
Duration:
- Modifier Duration Type:
Duration - Duration:
5(seconds) - Can Reapply: ✅ (checking this resets timer when reapplied)
Tags:
- Effect Tags: Add
"Haste"(used for both gameplay queries viaHasTag()and effect organization)
3.3 Add Visual Effects (Optional)¶
Cosmetic Effects:
- Size:
1 - Element 0:
- Prefab: Drag a particle system prefab (or create one)
- Requires Instancing: ✅ (creates a new instance per application)
Step 4: Apply the Effect (30 seconds)¶
Add this code to test your effect:
Test it:
- Assign
HasteEffectto the Inspector field - Press Play
- Press
Hto apply haste - Notice: Speed increases to 7.5, particle effect spawns
- After 5 seconds: Speed returns to 5, particles disappear
Step 5: Create a Stun Debuff (2 minutes)¶
Let's make a more complex effect that prevents movement.
5.1 Create the Effect¶
Right-click→Create→Wallstop Studios→Unity Helpers→Attribute Effect- Name it:
StunEffect
5.2 Configure Stun¶
Modifications:
- Attribute Name:
Speed - Action:
Override - Value:
0(completely override speed to 0)
Duration:
- Modifier Duration Type:
Duration - Duration:
3 - Can Reapply: ✅
Tags:
- Effect Tags:
"Stunned","Stun","Debuff","CC"(for gameplay queries and organization)
5.3 Query Tags in Gameplay¶
Test it:
- Press
Sto stun yourself - Try to move - you can't!
- After 3 seconds, movement returns
Step 6: Advanced Features (5 minutes)¶
Stacking Effects¶
Effects stack independently by default:
| C# | |
|---|---|
Manual Removal¶
| C# | |
|---|---|
Multiple Modifications Per Effect¶
One effect can modify multiple attributes:
Create "Berserker Rage" effect:
- Modification 1: Speed × 1.3
- Modification 2: AttackDamage × 2.0
- Modification 3: Defense × 0.5 (trade-off - more damage but less defense!)
- Duration: 10 seconds
- Tags:
"Berserker","Buff"
Infinite Duration Effects¶
For permanent buffs (e.g., equipment):
| C# | |
|---|---|
Common Patterns¶
Damage Over Time (DOT)¶
This keeps CurrentHealth as a regular gameplay field while the effect system triggers damage through behaviours.
Cooldown Reduction¶
Conditional Effects¶
Troubleshooting¶
"Should I use CurrentHealth as an Attribute?"¶
- No! Use
MaxHealthas an Attribute (modified by buffs), but keepCurrentHealthas a regular field (modified by damage/healing) - Why: CurrentHealth is modified by many systems (combat, regeneration, etc.). Using it as an Attribute causes state conflicts when effects and other systems both try to modify it
- Pattern: Attribute for max/cap, regular field for current/depleting value
- See: "Understanding Attributes: What to Model and What to Avoid" in the main documentation
"Attribute 'Speed' not found"¶
- Cause: Attribute name in effect doesn't match the field name in AttributesComponent
- Fix: Names must match exactly (case-sensitive):
Speednotspeed - Tip: Use Attribute Metadata Cache generator for dropdown validation
Effect doesn't apply¶
- Check: Does target GameObject have an
AttributesComponent? - Check: Is
EffectHandlercomponent added? (Usually added automatically) - Check: Are there any errors in the console?
Particles don't spawn¶
- Check: Cosmetic Effects → Prefab is assigned
- Check: Prefab has a
CosmeticEffectDatacomponent - Check: Requires Instancing is checked if using per-application instances
Value isn't changing¶
- Check: Attribute name matches exactly
- Check: Modification value is non-zero
- Check: Action type is correct (Multiplication needs > 0, Addition can be negative)
- Debug: Log
attribute.Valuebefore and after applying effect
Next Steps¶
You now have a complete buff/debuff system! Here are some ideas to expand:
Create More Effects¶
- Shield: MaxHealth × 1.5, visual shield sprite
- Slow: Speed × 0.5, "Slowed" tag
- Critical Strike: AttackDamage × 2.0, "CriticalHit" tag, brief flash effect
- Invisibility: Just tags ("Invisible"), no stat changes, transparency effect
- Armor Buff: Defense + 10, metallic sheen cosmetic
- Strength Potion: AttackDamage × 1.5, red particle aura
Build Systems Around Tags¶
Designer Workflows¶
- Create an effect library (30+ common effects)
- Designers mix/match on items, abilities, enemies
- Programmers never touch effect code again!
📚 Related Documentation¶
Core Guides:
- Effects System Full Guide - Complete API reference and advanced patterns
- Getting Started - Your first 5 minutes with Unity Helpers
- Main README - Complete feature overview
Related Features:
- Relational Components - Auto-wire components (pairs well with effects)
- Serialization - Save/load effects and attributes
Need help? Open an issue
Made with ❤️ by Wallstop Studios¶
Effects System tutorial complete! Your designers can now create gameplay effects without code.