How to get Gameplay Effect Magnitude before applying Effect?

I know its abit late but maybe someone get food for thoughts from this. i found some hacky solution to predict Gameplay effect change values without dissecting whole system into bits.
First you have to deep copy ability component:

UPJCAbilitySystemComponent* UPJCAbilitySystemComponent::CreateAbilityComponentCopy()
{
	auto AbilitySystemComponentCopy = DuplicateObject(this,this->GetOwner());
	AbilitySystemComponentCopy->SetOwnerActor(this->GetOwnerActor());
	AbilitySystemComponentCopy->RemoveAllSpawnedAttributes();

	TArray<UAttributeSet*> AttributeSets;
	for(auto AttSet:this->GetSpawnedAttributes())
	{
		auto NewSet = DuplicateObject(AttSet,this->GetOwner());
		AttributeSets.Add(NewSet);
	}
	AbilitySystemComponentCopy->SetSpawnedAttributes(AttributeSets);

	
	AbilitySystemComponentCopy-> GetActiveGameplayEffectsMutable().RegisterWithOwner(AbilitySystemComponentCopy);
AbilitySystemComponentCopy-> GetActiveGameplayEffectsMutable().CloneFrom(ActiveGameplayEffects);

// this is needed if bSupressGameplayCues false.
	/*AbilitySystemComponentCopy->AbilityActorInfo = TSharedPtr<FGameplayAbilityActorInfo>(UAbilitySystemGlobals::Get().AllocAbilityActorInfo());*/
	AbilitySystemComponentCopy->bSuppressGameplayCues = true;
	return AbilitySystemComponentCopy;
}

Then create a prediction function of somekind :

		TMap<FGameplayAttribute,float> Result;
		
		auto AbilitySystemCompCopy = AbilitySystem->GetAbilityComponentCopy();
		AbilitySystemCompCopy->ApplyGameplayEffectToSelf(GameplayEffect,0,Context);
		
		TArray<FGameplayAttribute> SourceAttributes;
		AbilitySystem->GetAllAttributes(SourceAttributes);
		for(auto const &Attribute: SourceAttributes)
		{
			float SourceValue = AbilitySystem->GetNumericAttribute(Attribute);
			float TargetValue = AbilitySystemCompCopy->GetNumericAttribute(Attribute);
			if (!(TargetValue == SourceValue))
			{
				
				Result.Add(Attribute,TargetValue - SourceValue );
			}
		}
2 Likes