UGameplayModMagnitudeCalculation - Can't get FGameplayAttributeData captured value
I'm making an RPG game, and I'm using GameplayAbilities plug-in. Everything was excellent until now, so I'll try to explain my problem in detail.
I want to use custom calculation class for applying damage. I've setup GameplayEffect to use custom calculation class derived from UGameplayModMagnitudeCalculation. I made a blueprint from my custom calculation class and selected relevant attributes to capture. I'm planning to use those values to calculate damage (only using one at the moment, for presentational purposes).
UGameplayModMagnitudeCalculation class has this:
All fine, I can override this in blueprint.
I created BlueprintCallable UFUNCTION
in my class that will get the value that I need to pass that value to CalculateBaseMagnitude in Blueprint. Except I have a problem getting the value. I think that I pinpointed the problem, and it's casting to my class that holds GameplayAttributes derived from AttributeSet. This should've done it:
I tried different types of casts (const, static, dynamic), and nothing works. After using CastChecked, I'm getting this error: Fatal error: [File:\Build\++UE4\Sync\Engine\Source\Runtime\CoreUObject\Private\Templates\Casts.cpp] [Line: 10] Cast of Class /Script/UrathaTheFirstHunt.UrathaTalentSet to UrathaTalentSet failed
GetAttributeSetClass()->GetFullName returns /Script/UrathaTheFirstHunt.UrathaTalentSet and not UrathaTalentSet. Is this some kind of problem I'm not aware of?
Thanks in advance!
GetNumericValueChecked asks for const UAttributeSet* ; UUrathaTalentSet is derived from UAttributeSet; BUT GetAttributeSetClass return UClass* ; That's why I'm casting to my UUrathaTalentSet class. I tried this as well, and no luck:
I solved it by doing a workaround that I'm not proud of.
I expanded the UFUNCTION parameters, since FGameplayEffectSpec is available in the GetBaseMagnitude:
This UFUNCTION is called inside a blueprint override of GetBaseMagnitude, and it has to be a const UFUNCTION.
FGameplayEffectSpec contains the specification of GameplayEffect that is being applied. I have everything there except the FGameplayAttributes that I need. That was the whole point of having a custom calculation class blueprint - so I could add FGameplayAttributes that are needed for calculation.
So, this the blasphemy that I came up with:
And this works. Not how I intended, but it's a workaround. It contains some NO-NOs, like getting components by name (strings).
I really hope that someone had a similar problem, so we can solve it together, because calculation class should calculate, not provide lookup strings.
Follow this question
Once you sign in you will be able to subscribe for any updates here