[GAS] Need help with architecture approach

Hey, someone experienced with GAS?
I’m thinking on a system architecture where abilities can have stats like damage and cooldown. Will also have game effect perks that can affect ability stats. Like +10% increase damage or -10% GCD. Now the hard part is how should I manage all this?

I see attributes can handle similar fuctionality automatically. And I have attributes working on character and updated by GameEffects. But there are no attributes for the abilities as I can see :face_with_raised_eyebrow:

So ideas:

  1. So the simple logic is to have a cache with the precalculated data for abilities. Once user receive perk the cache gets updated and when ability is fired the data from cache is used to supply damage values and CD. This approach requires extensive coding which I prefer to avoid.
  2. Maybe I can use character attributes though? Upon giving character an ability I can add new attributes related to an ability and apply effects affecting them all. Then when ability is activated I query character for needed attributes. Don’t know if it even possible yet.

Have to come up with an idea.

sounds like you are kind of talking about a Data Driven architecture

you could check this out: Working with Data in Unreal Engine 5 | Unreal Fest 2022 - YouTube to see if it could help.
for the most part with things like DataTables (that can have pointer to Blueprints if need be) you only need to define the struct for a DataTable Row, and then a few helper functions and then use your data by querying the DataTableRow Struct.

though keep in mind that DataTables are unchangeable at runtime, so you might need to do work on the data for scalings, and DataTables are unique FName resolved at runtime (similar to a TMap<FName, MyStruct>)

for getting the character Attributes that is a matter of having a reference or pointer some how and accessible properties and/or function calls. if the Ability to “created by” the Pawn then have a pointer to the Pawn be a member of the Ability and just get the values from the Pawn (this also works for ActorComponents attached to the Pawn)

this is one approach that would utilize a Data driven approach which might be too rigid for your needs, but the Video does go into other options as well.

I know, but I need a specific solution using the Gameplay Ability System (GAS).

I’ve tried to implement #2 case but struggling while trying to add dynamic attributes to character GAS.

image

void ACharacterBase::AddAttributes(const TSubclassOf<class UGameplayEffect> Attributes) const
{
	if (!AbilitySystemComponent.IsValid())
		return;

	if (!Attributes)
	{
		return;
	}

	FGameplayEffectContextHandle EffectContext = AbilitySystemComponent->MakeEffectContext();
	EffectContext.AddSourceObject(this);
	//create instance of effect
	const FGameplayEffectSpecHandle NewHandle = AbilitySystemComponent->MakeOutgoingSpec(Attributes, 1, EffectContext);
	
	if (NewHandle.IsValid())
	{
		auto Handle = AbilitySystemComponent->ApplyGameplayEffectSpecToSelf(*NewHandle.Data.Get());
	}

}

ApplyGameplayEffectSpecToSelf is executed but attributes aren’t added and granted ability isn’t given :frowning:

The game Effect I use is pretty straightforward

if you throw in Log statements

UE_LOG(LogTemp, Warning, TEXT("Made it here"));

// "no attributes leaving"
// "Handle not valid"

at different points in the functions where does it stop that it shouldn’t? does the function/event ever get invoked in the first place?

Yeah, I’m debugging it live. It runs through all the statements but just don’t work

PS: Okay the granted ability part is solved. Atrributes still haven’t been granted…

I’m not sure that I use the correct approach at all. That’s why I need an advice how to implement the system I want.

So I decided to go with a different attribute set for each ability and a single ASC. I give character an ability along with all of its attributes. It allows attributes to be affected by different increases and reductions which are applied automatically.

Not sure if it is the best way to go since no one helped me with GAS yet. Will see.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.