GAS, Data can't be stored in Ability

Hello
I’ve a problem with the GAS System.
I’ve added a variable to it and set it to be instanced only once per actor.
Ability
I set the variable in the ability, I check it right after and it is set sucessfully.
But when I want to read it in the magnitude calculation, its empty.
I’ve checked whether it is instanced multiple times, but it is only instanced once.
Its empty anyway.

	const UTestAbility* ContextAbility = Cast<UTestAbility>(Spec.GetEffectContext().GetAbility());
	ContextAbility->Target;

Why is that the case?
Also, can I access the target direcly from the FGameplayEffectSpec? If so where is it stored?
Thanks for your answer.

Hi, I managed to get active ability’s data as:

    FGameplayAbilitySpec* AbilitySpec = ...; //Your ability spec, assuming you have one
    TArray<UGameplayAbility*> InstancesList = AbilitySpec->GetAbilityInstances();
	for (UGameplayAbility* Ability : InstancesList)
	{
		if (Ability)
		{
			// Some code using Ability, which will have all runtime-set data
		}
	}

It seems that other means returns CDO or something similar, I didn’t dig too deep into it yet.

1 Like

Are you setting it on the client and checking it on the server?
Or are you setting it on the server, and the client hasn’t gotten it replicated yet?
(Or maybe it’s not replicated at all?)

1 Like

Hello
Thank you very much for your answers.

@IrSoil You’re right, if I set and read the variable on the instance it works just fine. But if I set it in the Blueprint ability as in the screenshot, and read it through the seemingly (one and only) instance its just empty.
The only explenation I have is that the node always creates a new instance.

@jwatte I deactivated all networking to limit possible errors, so everything should run with authorithy. But I’ve also expected, that when I set Net Execution Policy to server instantiated or predicted, that a local instance would exist always individually. So one instance of the ability on the server and one on the client.

Personally I’m using UMyGameplayAbility, with additional FGameplayTagContainer to hold custom data. I’m manage content of this TagContainer by “MyAdd(tag)” & “MyRemove(tag)” exposed to blueprints and read data from inside AbilitySystemComponent as I shown above. So, i’m set tags I need from ability’s blueprint and read them from another place in c++ code.

Probably this approach may be applicable to your goals.

1 Like