[text] Dynamic Binding Example

Viewer

copydownloadembedprintName: Dynamic Binding Example
  1. /// "GrabLeft" is an FName for identifying the binding setting in the project settings
  2. /// currentInputMappings->GrabLeft is a TSubclassOf<UGameplayTask>
  3. BindButtonPressWithRelease("GrabLeft", currentInputMappings->GrabLeft, EControllerHand::Left);
  4.  
  5.  
  6. void APlayerCharacter_VR::BindButtonPressWithRelease(FName binding, TSubclassOf<UBehavior_Player> inClass, EControllerHand inHand)
  7. {
  8.         if (IsValid(inClass))
  9.         {
  10.             InputComponent->BindAction<FPlayerTaskDelegate>(binding, IE_Pressed, this, &APlayerCharacter_VR::PlayerTaskClientServer, inClass, inHand);
  11.                 InputComponent->BindAction<FPlayerTaskDelegate>(binding, IE_Released, this, &APlayerCharacter_VR::PlayerInputRelease, inClass, inHand);
  12.                 BindReleaseInput(inClass, inHand);
  13.         }
  14. }
  15.  
  16.  
  17. /// Release Mappings is just an array of structs containing a TSubclassOf<UGameplayTask> as the key
  18.     /// an enum representing which hand
  19.     /// and the relevant DECLARE_DELEGATE(FReleaseDelegate);
  20. void APlayerCharacter_VR::BindReleaseInput_Implementation(TSubclassOf<UBehavior_Player> inClass, EControllerHand inHand)
  21. {
  22.         ReleaseMappings.Add(FReleaseInputMapping(inClass, inHand));
  23. }
  24.  
  25.  
  26. /// You can see here at line 31 the entry calls the FReleaseDelegate.ExecuteIfBound() from the input release struct
  27. void APlayerCharacter_VR::PlayerInputRelease_Implementation(TSubclassOf<UBehavior_Player> inClass, EControllerHand inHand)
  28. {
  29.         if (ReleaseMappings.Contains(TPair<TSubclassOf<UBehavior_Player>, EControllerHand>(inClass, inHand)))
  30.         {
  31.                 ReleaseMappings.FindByKey(TPair<TSubclassOf<UBehavior_Player>, EControllerHand>(inClass, inHand))->ReleaseMapping.ExecuteIfBound();
  32.         }
  33. }

Editor

You can edit this paste and save as new:


File Description
  • Dynamic Binding Example
  • Paste Code
  • 30 Sep-2022
  • 1.6 Kb
You can Share it: