Unreal four Gameplay Ability System introduction (11)-Ability and binding input

After writing ten articles, I found that I haven't talked about the Ability that GAS has been using. Here is a brief introduction to skills.

The relationship and interaction between the server and the client are not involved here, because I am not familiar with this aspect.

First, let's introduce the basic flow chart of Gameplay Ability. Picture from https://github.com/tranek/GASDocumentation#concepts-ga

First, try to start the Ability in Character or Controller, and then judge the Tag condition. If it can be started, enter activate Ability. Then it will judge whether the Cooldown and Cost conditions set in the skill can be met through Commit Ability. If not, enter EndAbility. Next, you can apply Gameplay Effect in Ability. Note that the conditions here are carried out in one frame.

More complicated is the use of the Ability Task, which can open an additional thread in the Ability. All the tasks that we used before, such as playing Montage, waiting for Event and so on, need to be executed for more than one frame, are Ability tasks.

Bind input to ASC

In ASC system, we can directly bind Input with Input without starting skills through Try Activate Ability. Here I will briefly introduce the method of binding Input.

Create enum

First, open the header file named after your project. My project name is GAS_, So this file is in the folder GAS_ In, the name is GAS_ h.

Define the enum class in it.

UENUM(BlueprintType)
enum class EAbilityInputID : uint8
{
   // 0 None
   None         UMETA(DisplayName = "None"),
   // 1 Confirm
   Confirm          UMETA(DisplayName = "Confirm"),
   // 2 Cancel
   Cancel       UMETA(DisplayName = "Cancel"),

   Ability1      UMETA(DisplayName = "Ability1"),
};

Open Project Setting and bind the Input with the same name in Input. Note that the name here should be consistent with that in enum.

Create a new derived class AbilityBase

UCLASS()
class GAS__API UGameplayAbilityBase : public UGameplayAbility
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="AbilityBase")
	EAbilityInputID AbilityInputID = EAbilityInputID::None;
};

Open character cpp

Bind the role's ASC to the Input Component in the role's SetupPlayerInputComponent.

void ACharacterBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	//......
	if(AbilitySystem)
	{
		// Bind to AbilitySystemComponent
		AbilitySystem->BindAbilityActivationToInputComponent(PlayerInputComponent, FGameplayAbilityInputBinds(FString("Confirm"), FString("Cancel"), FString("EAbilityInputID"), static_cast<int32>(EAbilityInputID::Confirm), static_cast<int32>(EAbilityInputID::Cancel)));
	}
}

Then create a function named GiveAbilityInput, and bind the ability input ID of the skill when adding a skill.

void ACharacterBase::GiveAbilityInput(TSubclassOf<UGameplayAbilityBase> Ability)
{
	if(AbilitySystem && HasAuthority() && Ability)
	{
		AbilitySystem->GiveAbility(FGameplayAbilitySpec(Ability, 1, static_cast<int32>(Ability.GetDefaultObject()->AbilityInputID), this));
	}
}

Create GA_Test

Set the Ability Input ID and click 1 after running the game to start GA automatically_ Test.

Ability Tags

Finally, let's talk about the label setting in skills.

Ability Tags: tag of the current skill.

Cancel Abilities with Tag: after the current skill is started, all other skills with these tags will be cancelled

Blocked Abilities with Tags: when this ability is running, other skills with this tag will be block ed and cannot be started..

Activation owned tags: when this ability is running, these tag s will be owned by the ASC to which the skill belongs.

Activation required tag: tags necessary for skill activation. ASC must have all these tags.

Activation blocked tag: if ASC has one tag, it cannot be started.

Source required tag: the ASC of source can be started only if it has all tags

Source blocked tag: the ASC of source has a tag, and the skills are blocked.

taget is similar.

Note that the concept of Source and skill owner is different.

There's another one later, and this tutorial is over.

Introduction to GAS

Keywords: Game Development unreal

Added by Dixen on Fri, 18 Feb 2022 16:06:57 +0200