Gameplay Ability - Long Lag on First Use

I have a situation that occurs on the very first use of a Gameplay Ability (the UE4 Gameplay Ability System). MY FIRST ABILITY IS REALLY SLOW (like 2-3 secounds of frozen screen lag). Once the first ability fires the rest are fine. This occurs 100% on each launch of the game and never reoccurs until I exit and relaunch.

From the Constructor:

// Abilities and Attributes
PlayerAbilitySystem = CreateDefaultSubobject<UF3CPlayer_AbilitySystemComponent>(TEXT("PlayerAbilitySystem"));
PlayerAbilitySystem->SetIsReplicated(true);
CoreAttributeSet = CreateDefaultSubobject<UCoreAttributeSet>(TEXT("CoreAttributeSet"));

Possessed By Logic has been added:

void AF3CCharacter::PossessedBy(AController * NewController)
{
	Super::PossessedBy(NewController);
	PlayerAbilitySystem->RefreshAbilityActorInfo();
}

From Begin Play I call an Initialization Routine in my Abiliity Component

void UF3CPlayer_AbilitySystemComponent::InitializeManager(AF3CCharacter* OwningCharacter)
{

	// Null check
	if (OwningCharacter == nullptr)
	{
		UE_LOG(LogTemp, Warning, TEXT("No Character passed to Cache.  Player_AbilitySystemComponent::InitalizeManager"));
		return;
	}

	if (ActiveAbilities.Num() == 0)
	{
		UE_LOG(LogTemp, Warning, TEXT("No Items defined in array.  Player_AbilitySystemComponent::InitalizeManager"));
		return;
	}


	CharacterCache = OwningCharacter;
	Initalized = true;
	AbilityWidgets = CharacterCache->HUDWidget->GenerateAbilityWidgets(this, AbilityWidgetTemplate);
		
	// Loop through and grant the abilities and set up the ability bar based on the active abilities array
	for (int32 i = 0; i < ActiveAbilities.Num(); i++)
	{
		// Assign Abilities (Always on the server)
		if (CharacterCache->Role == ROLE_Authority)
		{
			// Not Null check for the ability property
			if (ActiveAbilities[i])
			{
				GiveAbility(FGameplayAbilitySpec(ActiveAbilities[i].GetDefaultObject(), 1, 0));
				UE_LOG(LogTemp, Log, TEXT("Player_AbilitySystemComponent: Granted Ability."));
			}
		}
		// Draw the ability buttons
		UpdateAbilityDisplay(ActiveAbilities[i]);

	}
	if (CharacterCache->Role == ROLE_Authority)
		InitAbilityActorInfo(OwningCharacter, OwningCharacter);
	
	UE_LOG(LogTemp, Log, TEXT("Player_AbilitySystemComponent: InitializeManager Completed."));
}

I am calling the abilities using the TryActivateAbility from Blueprint.

It might be creating the pool of cues - this was certainly an issue in the past. This happens if you don’t specify the cue path, for example in DefaultGame.ini

[/Script/GameplayAbilities.AbilitySystemGlobals]
+GameplayCueNotifyPaths="/Game/MyProject/My/Folder/With/All/My/Cues"

This will search all folders below for cue objects to instance when the cue manager is created (on launch). You should be seeing a warning in your log stating that no cue path has been specified and it’s searching your whole project. I believe you can get additional control over which cues are loaded and when using cue sets.

1 Like

Coming back after some testing to confirm that adding these lines to my DefaultGame.ini solved the delay problem!

[/Script/GameplayAbilities.AbilitySystemGlobals]
+GameplayCueNotifyPaths="/Game/AbilitySystem"

Loading all GameplayCues lazily might not be a good solution. Check this link for more: