Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UGameplayModMagnitudeCalculation - Can't get FGameplayAttributeData captured value

Hey guys!

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:

 UFUNCTION(BlueprintNativeEvent, Category="Calculation")
 float CalculateBaseMagnitude(const FGameplayEffectSpec& Spec) const;

All fine, I can override this in blueprint.

I created BlueprintCallable UFUNCTION

 UFUNCTION(BlueprintCallable, Category = "Calculation")
 float GetMagnitudePerAttribute(FGameplayEffectAttributeCaptureDefinition captureAttribute) const;

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:

 return captureAttribute.AttributeToCapture.GetNumericValueChecked(CastChecked<UUrathaTalentSet>(captureAttribute.AttributeToCapture.GetAttributeSetClass()));

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!

Extra info:

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:

 return captureAttribute.AttributeToCapture.GetNumericValueChecked(CastChecked<UUrathaTalentSet>(captureAttribute.AttributeToCapture.GetUProperty()->GetOuter()));
Product Version: UE 4.21
more ▼

asked Jan 31 '19 at 08:32 AM in C++ Programming

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

 UFUNCTION(BlueprintCallable, Category = "Calculation") 
 float GetMagnitudePerAttribute(FGameplayEffectSpec spec, FGameplayEffectAttributeCaptureDefinition captureAttribute) const;

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:

 //Instigator is a player character (AUrathaCharacter in my case).
 auto talentSet = (UUrathaTalentSet)spec.GetContext().GetInstigator()->GetSubobjectByName("UrathaAttributeTalentSetComponent");
 //GetAttribute(FName name) is my method for getting the FGameplayAttribute by using reflection.
 //Only using the FGameplayAttribute name from custom calculation class. :(
 return talentSet->GetAttribute(*captureAttribute.AttributeToCapture.AttributeName)->GetCurrentValue();

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.

more ▼

answered Feb 01 '19 at 12:06 PM

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question