GASShooter icon indicating copy to clipboard operation
GASShooter copied to clipboard

Overriding CheckCost() can lead to crashes if GetCurrentSourceObject is called during the cost check and debug is displayed.

Open MOTYSHIZ opened this issue 2 years ago • 1 comments

When debug information for an ability is displayed (third category when showing AbilitySystem debug), CanActivateAbility is called, which then calls CheckCost. This means that CheckCost gets called on the CDO, so attempting to get a reference to the source object in CheckCost will cause GetCurrentSourceObject to call GetCurrentAbilitySpec, which will not be valid for the CDO.

image GI_GameplayAbility line 43 is where I implement override CheckCost in the same way as GASShooter. image I overrode via BP and used a GetCurrentSourceObject node. image

GetCurrentAbilitySpec checks IsInstantiated, which detects that it is being called on the CDO, which leads to an assertion failure. image image

I may be able to solve this for my specific case by just caching the source object when the ability is instantiated instead of calling it during CheckCost. There should probably be some sort of warning comment above UGSGameplayAbility::CheckCost override to warn people to not call GetSourceObject in their cost checking override function though.

MOTYSHIZ avatar Jul 08 '22 15:07 MOTYSHIZ

Actually, the solution appears to be pretty simple. This worked for me. image

MOTYSHIZ avatar Jul 08 '22 16:07 MOTYSHIZ