diff --git a/README.md b/README.md index 8f3bb6e..08f6dbe 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,38 @@ Features: ##### InputConfig (GAS abilities input binding) -`bUseInputConfig` +Binding InputActions to GameplayAbilities using tags, like in Lyra but enhanced and adopted for 3d action game. + +![image](https://github.com/user-attachments/assets/2c72400e-1122-40b2-aa73-4bfc1e212d0f) + +Setup: + +- turn on `bUseInputConfig` on `UHLAbilitySystemComponent` +- create `InputConfig` - `DataAsset` nested from `UHLInputConfig` +- abilities should nest from `UHLGameplayAbility` for `ActivationPolicy` work correctly +- in `Project Settings -> Input -> Default Input Component Class` -> set `UHLInputComponent` +- in your PlayerCharacter class add lines in `SetupPlayerInputComponent` for bind actions from `InputConfig` + +```c++ +void AUHLPlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + + UUHLInputComponent* UHLInputComponent = CastChecked(PlayerInputComponent); + UUHLInputConfig* UHLInputConfig = AbilitySystemComponent->InputConfig; + TArray BindHandles; + UHLInputComponent->BindAbilityActions(UHLInputConfig, AbilitySystemComponent, &UUHLAbilitySystemComponent::AbilityInputTagPressed, &UUHLAbilitySystemComponent::AbilityInputTagReleased, BindHandles); + + if (UHLInputComponent) + { + UHLInputComponent->BindAction(UHLInputConfig->NativeInputAction_Move.InputAction, ETriggerEvent::Triggered, this, &AUHLPlayerCharacter::InputMove); + UHLInputComponent->BindAction(UHLInputConfig->NativeInputAction_Move.InputAction, ETriggerEvent::Completed, this, &AUHLPlayerCharacter::InputStopMove); + + UHLInputComponent->BindAction(UHLInputConfig->NativeInputAction_LookMouse.InputAction, ETriggerEvent::Triggered, this, &AUHLPlayerCharacter::InputLook); + UHLInputComponent->BindAction(UHLInputConfig->NativeInputAction_LookStick.InputAction, ETriggerEvent::Triggered, this, &AUHLPlayerCharacter::InputLook); + } +} +``` ##### AbilityInputCache @@ -355,14 +386,6 @@ Get names of actor components on object, usefull for [`GetOptions` UPROPERTY](ht #### `GetHighestPoint` -#### `InputSystem` - -Binding InputActions to tags like in Lyra but enhanced and adopted for 3d action game - -- abilities should nest from `UHLGameplayAbility` for "ActivationPolicy" work correctly -- SetupPlayerInputComponent - bind all from input config, `BindAbilityActions` -- `Project Settings -> Input -> Default Input Component Class` -> change on `UHLInputComponent` - ### LoadingUtilLibrary **UHLLoadingUtilLibrary** - loading utils from Lyra diff --git a/Source/UnrealHelperLibrary/Private/AbilitySystem/UHLAbilitySystemComponent.cpp b/Source/UnrealHelperLibrary/Private/AbilitySystem/UHLAbilitySystemComponent.cpp index d432c6d..9a9cf24 100644 --- a/Source/UnrealHelperLibrary/Private/AbilitySystem/UHLAbilitySystemComponent.cpp +++ b/Source/UnrealHelperLibrary/Private/AbilitySystem/UHLAbilitySystemComponent.cpp @@ -184,7 +184,7 @@ void UUHLAbilitySystemComponent::AbilitySpecInputReleased(FGameplayAbilitySpec& } } -void UUHLAbilitySystemComponent::AbilityInputTagPressed(const FGameplayTag& InputTag) +void UUHLAbilitySystemComponent::AbilityInputTagPressed(const FGameplayTag InputTag) { if (InputTag.IsValid()) { @@ -200,7 +200,7 @@ void UUHLAbilitySystemComponent::AbilityInputTagPressed(const FGameplayTag& Inpu } } -void UUHLAbilitySystemComponent::AbilityInputTagReleased(const FGameplayTag& InputTag) +void UUHLAbilitySystemComponent::AbilityInputTagReleased(const FGameplayTag InputTag) { if (InputTag.IsValid()) { diff --git a/Source/UnrealHelperLibrary/Public/AbilitySystem/UHLAbilitySystemComponent.h b/Source/UnrealHelperLibrary/Public/AbilitySystem/UHLAbilitySystemComponent.h index 0d7da1b..038779f 100644 --- a/Source/UnrealHelperLibrary/Public/AbilitySystem/UHLAbilitySystemComponent.h +++ b/Source/UnrealHelperLibrary/Public/AbilitySystem/UHLAbilitySystemComponent.h @@ -7,6 +7,7 @@ #include "Input/AbilityInputCache.h" #include "UHLAbilitySystemComponent.generated.h" +class UUHLInputConfig; class UUHLGameplayAbility; /** * @@ -39,6 +40,8 @@ class UNREALHELPERLIBRARY_API UUHLAbilitySystemComponent : public UAbilitySystem UPROPERTY(EditAnywhere, BlueprintReadWrite) bool bUseInputConfig = false; UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bUseInputConfig")) + UUHLInputConfig* InputConfig; + UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bUseInputConfig")) bool bUseAbilityInputCache = false; // if enabled - caching works only in predefined user windows - ANS_AbilityInputCache_CacheWindow // if disabled - works always @@ -55,12 +58,11 @@ class UNREALHELPERLIBRARY_API UUHLAbilitySystemComponent : public UAbilitySystem virtual void OnUnregister() override; /** Input Config **/ - // TODO DA_InputConfig, UHLGameplayAbility void ProcessAbilityInput(float DeltaTime, bool bGamePaused); virtual void AbilitySpecInputPressed(FGameplayAbilitySpec& Spec) override; virtual void AbilitySpecInputReleased(FGameplayAbilitySpec& Spec) override; - virtual void AbilityInputTagPressed(const FGameplayTag& InputTag); - virtual void AbilityInputTagReleased(const FGameplayTag& InputTag); + virtual void AbilityInputTagPressed(const FGameplayTag InputTag); + virtual void AbilityInputTagReleased(const FGameplayTag InputTag); /** Input Config **/ UFUNCTION(BlueprintCallable)