Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MOTYSHIZ opened this issue Jul 8, 2022 · 1 comment

Comments

@MOTYSHIZ
Copy link

MOTYSHIZ commented Jul 8, 2022

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
Copy link
Author

MOTYSHIZ commented Jul 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant