How-To: Grant Abilities from Equipment

Goal: make a weapon bring its own abilities, have those abilities read the item that granted them, and have everything revoked cleanly on unequip.

Prerequisites
How-To: Author an Equipment Definition, and a pawn whose Ability System Component is reachable through IAbilitySystemInterface.

1. Make sure the ASC can be found

The plugin finds the ASC with Epic's UAbilitySystemGlobals::GetAbilitySystemComponentFromActor on the component's owner, which honors IAbilitySystemInterface. Any ASC works - Epic's, yours, or one on a PlayerState - as long as that interface returns it from the pawn.

No ASC means no grants, but the equip still happens
If no ASC is found, the item equips, the actors spawn, and LogCrimsonEquipment warns that the grants were skipped. Nothing errors and nothing tells the player. When gear silently grants nothing, check this first.
Verify
With verbose logging on, equipping a definition that has grants logs what it granted. A missing ASC logs a warning naming the owner instead.

2. List the grants on the definition

The definition carries three engine-typed grant lists: GrantedAbilities (FCrimsonEquipmentAbilityGrant: ability class, level, optional input tag), GrantedEffects (FCrimsonEquipmentEffectGrant) and GrantedAttributeSets (FCrimsonEquipmentAttributeSetGrant). The manager grants them through the engine ASC on equip and revokes them with the stored FCrimsonEquipmentGrantedHandles on unequip. (CrimsonCore - requires all Crimson plugins) additionally honors AbilitySetsToGrant (ability-set data assets) through UCrimsonCoreEquipmentAbilitySetSubsystem; without CrimsonCore that list is ignored.

Open your definition's Class Defaults and fill Granted Abilities (ability class, level, input tag), Granted Effects and Granted Attribute Sets. That is the whole wiring - there is no code and no event.

Verify
Equip the item, then open the GAS debugger (showdebug abilitysystem) on the server: the granted abilities are on the pawn's ASC. Unequip and they are gone.

3. Base your abilities on UCrimsonGameplayAbility_FromEquipment

When the manager grants an ability, it passes the UCrimsonEquipmentInstance as the ability spec's source object. UCrimsonGameplayAbility_FromEquipment turns that into two accessors, so a shared ability can read the specific item that granted it.

NodeReturnsWhat it gives you
Get Associated EquipmentUCrimsonEquipmentInstance*The instance that granted this ability. Cast to your instance subclass for per-item state.
Get Source ObjectUObject*That instance's source object - your inventory item, if one was passed to Equip Item.

Right-click in the Content Browser -> Add -> Crimson Plugins -> Equipment -> Ability From Equipment to create a Blueprint child. In its graph, Get Associated Equipment -> Cast To your instance class, then read whatever per-item state you keep there.

Add the ability to the definition's Granted Abilities (step 2) rather than granting it directly, so it is revoked with the gear.

The ability must be instanced
Non Instanced abilities have no ability spec to read, so Get Associated Equipment cannot work. The class validates this at author time: a Non Instanced child fails data validation with a message saying so. Use Instanced Per Actor or Instanced Per Execution.
Only valid during activation
Get Associated Equipment reads the current ability spec. Called outside an active activation it returns null and logs a warning to LogCrimsonEquipment. Read it inside ActivateAbility and cache what you need.
Verify
Activate the ability with the weapon equipped: Get Associated Equipment returns the instance. Equip a different weapon of the same definition and it returns the new instance, with no change to the ability.

4. Understand when grants are revoked

Grant handles live on the equipment entry, not on the pawn. Unequip Item calls Take From Ability System for that entry before the entry is removed, so exactly the abilities that item brought are revoked and nothing else.

SituationWhat happens to the grants
Unequip ItemRevoked from the ASC, then the entry is removed.
Equipping into an occupied slotThe incoming item is granted first, then the displaced item is revoked - so a shared resource is never briefly unowned. See Concept: Slots and Displacement.
Swap Equipped Items / Move Equipped Item To SlotNothing is revoked or re-granted. Both only change slot assignments.
The component is torn downThe server force-unequips everything, which revokes the grants.
Restore From Save DataEverything currently equipped is force-unequipped (revoking its grants) before the saved entries are re-added and granted.
Handles are authority-only
FCrimsonAppliedEquipmentEntry::GrantedHandles is marked NotReplicated. Grants exist only on the machine that has the ASC authority, which is what GAS expects - clients see the effects of the abilities through normal GAS replication, not through this list.
Verify
Equip weapon A, then equip weapon B into the same slot. showdebug abilitysystem on the server shows B's abilities and none of A's, and at no point during the swap were the shared ones missing.

See also

  • How-To: Add Per-Item Logic
  • Concept: Slots and Displacement
  • API Reference