[GAS] Does anyone know how to wait for the ability to finish?

Well. Wont you guess: theres much simpler without having to do with the GameplayTags!

Make a sublass “UGameplayAbility_Crow”
Add an event “EventOn_AbilityEnded” that executes when virtual override function ‘EndAbility’ is ran.

Above comment method ‘ListenForGameplayAbilityEnd’ changes to:

UAsyncTaskGameplayAbilityEnded* UAsyncTaskGameplayAbilityEnded::ListenForGameplayAbilityEnd(UAbilitySystemComponent* abilitySystemComponent,  TSubclassOf<UGameplayAbility> abilityClass)
{
	if (!IsValid(abilitySystemComponent))
	{
		Print::Say("Couldn't create Task, missing ASC");
		return nullptr;
	}

	auto abilitySpec = abilitySystemComponent->FindAbilitySpecFromClass(abilityClass);
	if (abilitySpec == nullptr)
	{
		Print::Say("Couldn't create Task, Ability " + abilityClass->GetName() + " not found in ASC");
		return nullptr;
	}
	
	auto abilityInstance = abilitySpec->GetPrimaryInstance();
	if (abilityInstance == nullptr)
	{
		Print::Say("Couldn't create Task, Ability " + abilityClass->GetName() + " couldn't find an instance. Instance Policy shouldn't be 'instance per execution'");
		return nullptr;
	}
	
	UGameplayAbility_Crow* abilityCrow = Cast<UGameplayAbility_Crow>(abilityInstance);
	if (abilityCrow == nullptr)
	{
		Print::Say("Couldn't create Task, Ability " + abilityClass->GetName() + " needs to inherit from UGameplayAbility_Crow");
		return nullptr;
	}

	UAsyncTaskGameplayAbilityEnded* r = NewObject<UAsyncTaskGameplayAbilityEnded>();
	abilityCrow->EventOn_AbilityEnded.AddDynamic(r, &UAsyncTaskGameplayAbilityEnded::OnCallback);
	r->AbilityListeningTo = abilityCrow;

	return r;
}

Remember to do:

		AbilityListeningTo->EventOn_AbilityEnded.RemoveDynamic(this, &UAsyncTaskGameplayAbilityEnded::OnCallback);

In ‘OnCallback’ and ‘EndTask’

4 Likes