Actors which grant effects or abilities can usually share info about things through the context and spec.
Effects to Abilities
Simplest way to share info is via the effect context
FGameplayEffectContextHandle EffectContext = FGameplayEffectContextHandle(UAbilitySystemGlobals::Get().AllocGameplayEffectContext());
EffectContext.AddInstigator(this, this);
EffectContext.AddSourceObject(this);
const FActiveGameplayEffectHandle Handle = ASC->ApplyGameplayEffectToSelf(PickupEffect->GetDefaultObject<UGameplayEffect>(), 1, EffectContext);
If this effect grants some ability or some other piece of logic looks at it, it can read the instigator and source object values from the context. The source object could then be directly accessed, for example to get additional data that the effect might not carry within itself.
This can be done for example in OnAvatarSet
:
void UMyAbility::OnAvatarSet(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec)
{
const FActiveGameplayEffectHandle& EffectHandle = ActorInfo->AbilitySystemComponent->FindActiveGameplayEffectHandle(Spec.Handle);
if(EffectHandle.IsValid())
{
UObject* Source = ActorInfo->AbilitySystemComponent->GetEffectContextFromActiveGEHandle(EffectHandle).GetSourceObject();
//Now we have the source object from the gameplay effect context
//and we can do something with it. Be sure to check if it's valid though.
auto* Foo = Cast<AWhatever>(Source);
}
Super::OnAvatarSet(ActorInfo, Spec);
}