Skip to content

Gameplay Effects

sajad0131 edited this page Aug 7, 2025 · 1 revision

Gameplay Effects

Gameplay Effects are the primary mechanism for modifying attributes. They can be instant (like taking damage) or have a duration (like a buff or a poison effect).

Core Components

  • GameplayEffect: An abstract base ScriptableObject for all effects. It defines the duration, stacking behavior, and any GameplayTags granted to the target.
  • InstantModifierEffect: An effect that applies a one-time modification to an attribute.
  • DurationModifierEffect: An effect that applies a modification for a specific duration.
  • GameplayEffectRunner: A MonoBehaviour that manages the application and removal of active effects on a character.

How to Create an Effect

  1. Right-click in the Project window and go to Create > GAS > Effects.
  2. Choose either Instant Modifier or Duration Modifier.
  3. Configure the effect's properties in the Inspector.

Example: A "Fire Damage" Instant Effect

// In InstantModifierEffect.cs
[CreateAssetMenu(fileName = "NewInstantModifierEffect", menuName = "GAS/Effects/Instant Modifier")]
public class InstantModifierEffect : GameplayEffect
{
    [Header("Modifier")]
    public AttributeDefinition attribute;
    public ModifierType type;
    public float value;

    public override void Apply(GameObject target, GameObject instigator, int stackCount = 1)
    {
        var attributeSet = target.GetComponent<AttributeSet>();
        if (attributeSet == null || attribute == null) return;

        var attrValue = attributeSet.GetAttribute(attribute);
        if (attrValue == null) return;

        float modValue = value * stackCount;
        if (type == ModifierType.Flat)
        {
            attrValue.BaseValue += modValue;
        }
        else if (type == ModifierType.Percent)
        {
            attrValue.BaseValue *= (1 + modValue);
        }
    }
}
Clone this wiki locally