So if you switch to 3rd page of GAS debugger, while playingLyra, you will get a lot of messages like:
GetCurrentAbilitySpec cannot be called on a non-instanced ability. Check the instancing policy.
in your log.
While the ability itself is instanced per actor. It is a Lyra bug that actually made me think in wrong direction why my rifle ability doesn’t work. So how to fix this issue?
The problem is that in debugger ability cdos are called instead of instances. Further replace ECR with Lyra:
GetCurrentAbilitySpec()
is called in UECRGameplayAbility_FromEquipment::GetAssociatedEquipment()
. It is called by UECRAbilityCost_ItemTagStack::CheckCost()
, which is called by debugger. But debugger calls on abilities cdos, passing spechandle Lyra’s devs don’t use. To fix all that, I used spec to find actualy ability and it’s source object (weapon instance), then I added optional parameter for SourceObject
to GetAssociatedEquipment
:
UECREquipmentInstance* UECRGameplayAbility_FromEquipment::GetAssociatedEquipment(UObject* SourceObject) const
{
if (SourceObject)
{
return Cast<UECREquipmentInstance>(SourceObject);
}
if (FGameplayAbilitySpec* Spec = GetCurrentAbilitySpec())
{
return Cast<UECREquipmentInstance>(Spec->SourceObject);
}
return nullptr;
}
To functions that use it (GetWeaponInstance()). Then we can find actual ability instance by spec, eg in CheckCost(), when ability cdo is used instead of instance:
const FGameplayAbilitySpec* AbilitySpec = ActorInfo->AbilitySystemComponent.Get()->FindAbilitySpecFromHandle(Handle);
if (const UECRInventoryItemInstance* ItemInstance = EquipmentAbility->GetAssociatedItem(AbilitySpec->SourceObject)) ...
Also to UECRGameplayAbility_RangedWeapon::CanActivateAbility
:
FGameplayAbilitySpec* AbilitySpec = ActorInfo->AbilitySystemComponent.Get()->FindAbilitySpecFromHandle(Handle);
if (GetWeaponInstance(AbilitySpec->SourceObject) == nullptr) ...