Community Tutorial: On Tick Ability Task

By default, Gameplay Abilities do not support ticking, and this is done by design and intention. However, there may be abilities that require tick functionality, and this Ability Task handles just that.

Assumptions are that you have added GAS to your project and know C++/Blueprint programming.

https://dev.epicgames.com/community/learning/tutorials/qZYY/unreal-engine-on-tick-ability-task

3 Likes

Hello @DevinSherry
Thank you for providing your code! :slight_smile:
I was wondering, could you elaborate a bit more on this topic :

Gameplay Abilities do not support ticking, and this is done by design and intention

Or perhaps point me to the place where Epic staff addresses this issue and explain why they intentionally make gameplay ability un-tickable?

Thank you!

2 Likes

" * Gameplay Abilities do not carry out their primary work in a “tick” function like Actors and Components do. Instead, they launch Ability Tasks during activation which do most of the work asynchronously, and then handle the output of those Tasks by hooking into Delegates (in C++) or connecting nodes to output execution pins (in Blueprints)."

1 Like

Hi, one comment: you should call the UAbilityTask::ShouldBroadcastAbilityTaskDelegates function before broadcasting your delegate, so the tick function should look more like this:

	void UHeroAbilityTask_OnTick::TickTask(float DeltaTime)
	{
		Super::TickTask(DeltaTime);
		if (ShouldBroadcastAbilityTaskDelegates())
		{
				OnTick.Broadcast(DeltaTime);
		}
	}
2 Likes

Thank you for the comment :slight_smile: I’ve updated the snippet code accordingly!

2 Likes

You’re welcome! And, oh, I have a few more comments actually :sweat_smile:

The TaskDeltaTime variable from the header file looks redundant.

Also, the TaskInstanceName parameter from the UHeroAbilityTask_OnTick::AbilityTaskOnTick does nothing, because you’re not using it. That function should look more like this:

UHeroAbilityTask_OnTick* UHeroAbilityTask_OnTick::AbilityTaskOnTick(UGameplayAbility* OwningAbility, FName TaskInstanceName)
	{
		UHeroAbilityTask_OnTick* MyObj = NewAbilityTask<UHeroAbilityTask_OnTick>(OwningAbility, TaskInstanceName);
		return MyObj;
	}
2 Likes