GAS ability activation Input setup used by GAS-Shooter example

I am researching the GAS-Shooter example on Github

I would like to know how it implements ability activation using key press, specifically its sprint ability activated by left shift.

I know there many ways to activate ability via key press , example using Enhanced input component, but GAS-Shooter method does not use Enhanced input plugin. I am trying to undertand how this particular example does it.

I have followed everything done by the sample to add my own sprint ability but it does not work, ability is never called when i press left shift.

When i enable the GAS debugger i can see my GA_Sprint ability has been granted to the character, but the shift key does not activate the sprint ability, The sprint ability just prints message screen.

I have created an array for pairing bytes and input tags

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

};

I setup the GAS component input

void AC_GasCharacterBase::mfo_BindASCInput()
{
	

	if (!InputComponent)
	{
		verifyf(false, TEXT("ASC input bind failed - invalid InputComp"));
	}

	if (!mvo_pGasComp)
	{
		verifyf(false, TEXT("ASC input bind failed - invalid GasComp"));
	}

	if (mvo_bASCInputBound)
	{
		GLog->Logf(	TEXT("Char asc input setup called again ")	);
	}
	else
	{
		mvo_pGasComp->BindAbilityActivationToInputComponent(
			InputComponent,
			FGameplayAbilityInputBinds(FString("ConfirmTarget"),
				FString("CancelTarget"), FString("E_AbilityInputID"), static_cast<int32>(E_AbilityInputID::Confirm), static_cast<int32>(E_AbilityInputID::Cancel))
		);

		mvo_bASCInputBound = true;

	}



}

GAS input setup is called at ned of SetupPlayerInputComponent

void AC_GasCharacterBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	mfo_BindASCInput();
}

I give the sprint ability to my test character

void AC_GasCharacterBase::mfo_AddCharacterAbilities()
{


	// Grant abilities, but only on the server	
	if (GetLocalRole() != ROLE_Authority || !IsValid(mvo_pGasComp) || mvo_bCharacterAbilitiesGiven)
	{
		return;
	}

	mvo_pGasComp->GiveAbility(
		FGameplayAbilitySpec(mvo_sprintAbility, 1, static_cast<int32>(mvo_SprintGasInputID),this)
	);

	
	mvo_bCharacterAbilitiesGiven = true;


}

character given sprint ability i its PossessedBy by override

void AC_GasCharacterBase::PossessedBy(AController* NewController)
{
	mfo_AddCharacterAbilities();
}

Created very simple sprint ability blueprint that just prints message on activation. But does not work no message, ability activation code is never called.

Any pointers as to how GAS-Shooter implements ability activation with key press would be very much appreciated.
cheers

1 Like

Have you created an Sprint input action like this?

1 Like

Thanks for the feedback

I have added Sprint key input as shown below

Cheers