← Back to all addons

Requiring A Certain Weapon to Use Certain Abilities

Posted by SvanDark on Dec 7, 2025 at 4:56 PM

Gameplay3.0 Verified
💡 3

As the title says

  1. Open your AbilitySheet Script and add this at the top (in the namespace):
public enum EWeaponType
{
    None,
    Sword,
    Bow,
    Staff,
    // add more as needed: Dagger, Axe, etc.
}
  1. Still in the AbilitySheet Script, add weapon requirements fields & helpers
[Header("Weapon Requirement")]
[SerializeField] private EWeaponType m_requiredWeaponType = EWeaponType.None;

public EWeaponType requiredWeaponType => m_requiredWeaponType;

// true if no requirement OR equipment matches
public bool IsWeaponCompatible(Equipment equipment)
{
    if (m_requiredWeaponType == EWeaponType.None)
        return true;

    if (!equipment || !equipment.isWeapon)
        return false;

    return equipment.weaponType == m_requiredWeaponType;
}

public string GetWeaponRequirementMessage()
{
    if (m_requiredWeaponType == EWeaponType.None)
        return "You can't use this right now.";

    return $"You can't use this right now. Required weapon: {m_requiredWeaponType}";
}
  1. Now go into your Equipment Script and replace it with this:
[CreateAssetMenu(menuName = AssetMenuIndexer.Mythril2D_Items + nameof(Equipment))]
public class Equipment : Item
{
    [Header("Equipment")]
    [SerializeField] private EEquipmentType m_type;
    [SerializeField] private Stats m_bonusStats;
    [SerializeField] private SpriteLibraryAsset m_visualOverride;
    [SerializeField] private AbilitySheet[] m_bonusAbilities;

    [Header("Weapon Settings")]
    [SerializeField] private bool m_isWeapon = false;
    [SerializeField] private EWeaponType m_weaponType = EWeaponType.None;

    public EEquipmentType type => m_type;
    public Stats bonusStats => m_bonusStats;
    public SpriteLibraryAsset visualOverride => m_visualOverride;
    public AbilitySheet[] bonusAbilities => m_bonusAbilities;

    public bool isWeapon => m_isWeapon;
    public EWeaponType weaponType => m_weaponType;
}
  1. Now go into your CharacterBase Script and add this method:
/// <summary>
/// Shows the weapon requirement message while pausing the game.
/// </summary>
private async void ShowWeaponRequirementMessagePaused(AbilitySheet sheet)
{
    string msg = sheet.GetWeaponRequirementMessage();

    float previousTimeScale = Time.timeScale;
    Time.timeScale = 0f;

    try
    {
        await GameManager.DialogueSystem.Main.PlayNow(msg);
    }
    finally
    {
        Time.timeScale = previousTimeScale;
    }
}
  1. Still in CharacterBase, replace public EAbilityFireCheckResult FireAbility(ITriggerableAbility ability) with:
public EAbilityFireCheckResult FireAbility(ITriggerableAbility ability)
{
    ActiveAbilityBase abilityBase = ability.GetAbilityBase();

    // ───── Weapon requirement check (main + off-hand) ─────
    if (abilityBase != null && abilityBase.baseAbilitySheet != null)
    {
        AbilitySheet sheet = abilityBase.baseAbilitySheet;

        // Get currently equipped weapons
        Equipment mainWeapon = GameManager.InventorySystem.GetEquipment(EEquipmentType.Weapon);
        Equipment offWeapon  = GameManager.InventorySystem.GetEquipment(EEquipmentType.OffHand);

        bool compatible =
            sheet.IsWeaponCompatible(mainWeapon) ||
            sheet.IsWeaponCompatible(offWeapon);

        if (!compatible)
        {
            ShowWeaponRequirementMessagePaused(sheet);
            return EAbilityFireCheckResult.Unknown;
        }
    }
    // ──────────────────────────────────────────────────────

    EAbilityFireCheckResult triggerAbilityCheckResult = ability.CanFire();

    if (triggerAbilityCheckResult == EAbilityFireCheckResult.Valid)
    {
        GameManager.NotificationSystem.audioPlaybackRequested.Invoke(abilityBase.abilitySheet.fireAudio);

        bool isAbilityStateAutomaticallyManaged =
            abilityBase.baseAbilitySheet.abilityStateManagementMode
                == ActiveAbilitySheet.EAbilityStateManagementMode.Automatic;

        if (abilityBase.abilitySheet.updateLookAtDirectionOnFire)
        {
            SetLookAtDirection(GetTargetDirection());
        }

        if (isAbilityStateAutomaticallyManaged)
        {
            abilityBase.gameObject.SetActive(true);
            ability.Fire(() => abilityBase.gameObject.SetActive(false));
        }
        else
        {
            ability.Fire(null);
        }
    }

    return triggerAbilityCheckResult;
}

IMPORTANT: Make sure that your weapons has IsWeapon CHECKED, otherwise it won’t work

Now you should find those fields on your abilities, and weapons!

💬 Comments (8)

Dolph [Arithmyth] Dec 07, 2025 at 05:23 PM
@SvanDark very interesting! How are you using this in your gameplay?
SvanDark Dec 07, 2025 at 05:23 PM
It atleast effects the gameplay a lot for me, but i could be wrong with the tags
SvanDark Dec 07, 2025 at 05:24 PM
basically in my game i have one class and he can buy new abilities from class trainers, meaning that you can play 2 classes at once (due to being able to have 2 weapons), so it affects a lot of gameplay for me
Dolph [Arithmyth] Dec 07, 2025 at 07:26 PM
That’s really neat! Thanks for explaining it.
Nolyn_Bittle Dec 07, 2025 at 07:37 PM
So does this add-on give weapons the ability to give an unlockable tree of abilities ( the reason I ask is because you can already have weapons give the player certain abilities while equipped and taking them away when not equipped no changes needed)
SvanDark Dec 07, 2025 at 07:39 PM

i’m not sure i quite understand, the reason behind this addon is to make certain abilities require a certain weapon to use

For example if i wanna use quick shot i’ve got to have a Bow equipped, and if i don’t this text pops up and i cant cast the ability

Nolyn_Bittle Dec 07, 2025 at 07:51 PM
oh I see thanks for showing I understand now, the way i was doing this was by having the item add the ability and take away the ability which comes stock with mythril
SvanDark Dec 07, 2025 at 07:51 PM
ahhh, yeah my game works a little different lol

Want to continue the conversation?