[GAS] CalculateBaseMagnitude_Implementation (FGameplayEffectSpec& Spec) GetSourceObject returns null. Why?

As the title. I am implementing GAS and have a custom attribute calculation created in C++. When implementing CalculateBaseMagnitude_Implementation, the Spec parameter is fine in most regards except that the Spec.GetContext().GetSourceObject() function returns null back, so I cannot get the object calling, which I need.

Screenshot shows the custom attribute in editor.

Screenshot shows trying to use it in code but GetSourceObject is failing.

Now one thing someone is going to point out immediately is I am setting this to an interface and that the interface may not be properly set. This is however just fine. When I changed this line to just send back auto it was still returning null, indicating GetSourceObject() itself was not sending anything back regardless.

When does the source object get populated?

Seems like GetEffectCauser is sending me the data I need, which gives me a work around but I am curious as to GetSourceObject() now (the 5.2 project I am basing my work on looks like it became the victim of some moderate refactoring of the GAS system in 5.3)

Before you apply the gameplay effect, by calling ApplyGameplayEffectSpecToSelf() somewhere, you create a GameplayEffectContextHandle. On that GameplayEffectContextHandle you can set the source object, causer etc. like so:

FGameplayEffectContextHandle GameplayEffectContextHandle = AbilitySystemComponent->MakeEffectContext();
GameplayEffectContextHandle.AddSourceObject(this);
GameplayEffectContextHandle.Get()->SetEffectCauser( this );
1 Like