Download

GameplayAbilties AbilitySystemComponent input handling

I’m working with the GameplayAbilities system, and I’m having trouble understanding how the Input handling works for the AbilitySystemComponent.

There is a ‘GameplayAbilitiesSet.h’ class that shows a way to give multiple abilities to the AbilitySystemComponent, which includes an input designation as shown here:



/**
 *	This is an example input binding enum for GameplayAbilities. Your project may want to create its own.
 *	The MetaData default bind keys (LMB, RMB, Q, E, etc) are a convenience for designers setting up abilities sets
 *	or whatever other data you have that gives an ability with a default key binding. Actual key binding is up to DefaultInput.ini
 *	
 *	E.g., "Ability1" is the command string that is bound to AbilitySystemComponent::ActivateAbility(1). The Meta data only *suggests*
 *	that you are binding "Ability1" to LMB by default in your projects DefaultInput.ini.
 */
UENUM(BlueprintType)
namespace EGameplayAbilityInputBinds
{
	enum Type
	{
		Ability1				UMETA(DisplayName = "Ability1 (LMB)"),
		Ability2				UMETA(DisplayName = "Ability2 (RMB)"),
		Ability3				UMETA(DisplayName = "Ability3 (Q)"),
		Ability4				UMETA(DisplayName = "Ability4 (E)"),
		Ability5				UMETA(DisplayName = "Ability5 (R)"),
		Ability6				UMETA(DisplayName = "Ability6 (Shift)"),
		Ability7				UMETA(DisplayName = "Ability7 (Space)"),
		Ability8				UMETA(DisplayName = "Ability8 (B)"),
		Ability9				UMETA(DisplayName = "Ability9 (T)"),
	};
}

/**
 *	Example struct that pairs a enum input command to a GameplayAbilityClass.6
 */
USTRUCT()
struct FGameplayAbilityBindInfo
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, Category = BindInfo)
	TEnumAsByte<EGameplayAbilityInputBinds::Type>	Command;

	UPROPERTY(EditAnywhere, Category = BindInfo)
	TSubclassOf<UGameplayAbility>	GameplayAbilityClass;
};


Its then converted into an int32 here when given to the ability:



AbilitySystemComponent->GiveAbility(FGameplayAbilitySpec(BindInfo.GameplayAbilityClass->GetDefaultObject<UGameplayAbility>(), 1, (int32)BindInfo.Command));


My problem is that I cannot figure out how to link designations from this enum to actual Action Mappings from DefaultInput.ini. Nor can I understand how to properly register the AbilitySystemComponent to an InputComponent. I’ve managed to use GiveAbility to provide an ability blueprint, which is then triggered by TryActivateAbilityUsingClass. I’ve spent today basically trying to figure this input method out, so that I can utilise the Input Pressed/Released commands within GameplayAbility class.

I know this system is still experimental, but any help with this would be hugely appreciated :).

I’ve safely managed to trigger an event (and a lot more) by using a C++ base character class which my blueprint character class inherits from, with wrappers around AbilitySystemComponent->GiveAbility and the key, AbilitySystemComponent->AbilityLocalInputPressed(0). I hope next Unreal update more functions can be exposed to Blueprints, especially these basically essential functions since without access to them, the AbilitySystemComponent is fairly useless.

In case anyone else is curious, the key is to basically give the abilities at, say Begin Play, and then using your action events you’ve already triggered, call AbilityLocalInputPressed(AbilityNum) and AbilityLocalInputReleased(AbilityNum). The AbilitySystemComponent doesn’t have any actual input handling, you simply feed it these events from the Action Mappings. That Ability Num is the 3rd parameter in the GiveAbility function. You should ideally set the numbers with something like an enum, such as from the AbilitySet class example from above. Basically, your assigning the ability a number, and then calling that number based on your input mappings (your RMB action event should trigger the ability system number of your RMB Ability).

Since my input mappings simply change the spell you want to cast with RMB, I’ve made it so that 0-9 on the keyboard change an ‘AbilityNum’ variable, which is then sent to my C++ wrapper function around what is basically AbilityLocalInputPressed(AbilityNum).

Next issue I am having is that the ‘Wait for Overlap’ task isn’t triggering in my Gameplay Ability blueprint (experimental), can’t seem to get it to trigger a response. The RootComponent is a Collision Sphere set to Overlap all, but its just not triggering. Its clearly a WIP function, but insanely useful since its the only way I can seemingly Wait for a collision event to happen without needing 2 separate Abilities.

^^^ And fixed, had to make a class where the Sphere collision primitive was actually the true root for it to work. Even if I set the updated component of the Projectile Movement, still needed to be the real root.