RemoveBindingByHandle: where can I find the Handle parameter?

Hi!

I’m using Unreal 5.3.2.

If I did:
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ARSPlayerController::MoveActionMethod);

and I want to remove this binding.

What do I have to do?

Do I have to use RemoveBindingByHandle? But which is the Handle parameter?

Thanks!

BindAction does return the handle you need, so just store it instead of discarding

BindAction has this signature:

template<class UserClass>
FEnhancedInputActionEventBinding & BindAction
(
    const UInputAction * Action,
    ETriggerEvent TriggerEvent,
    UserClass * Object,
    typename FEnhancedInputActionHandlerSignature::TUObjectMethodDelegate< UserClass >::FMethodPtr Func
) 

FEnhancedInputActionEventBinding is:

struct FEnhancedInputActionEventBinding : public FInputBindingHandle

And FInputBindingHandle has the following method:

uint32 GetHandle() const

What do you mean with “BindAction does return the handle you need”?

And also, what do I have to store it instead of discarding?

Thanks!

While my answer indeed was a bit incomplete, you pretty much found the solution correctly: FEnhancedInputActionEventBinding::GetHandle() will return the handle you should pass to EnhancedInputComponent::RemoveBindingByHandle().

So, as an example of all of this smashed together:

//header
TArray<uint32> Handles; 

//cpp
{
    auto EnhancedIC = Cast<UEnhancedInputComponent>(InputComponent);

    //...

    const auto& Binding = EnhancedIC->BindAction(Input.Action, ETriggerEvent::Triggered, this, &AMyController::MyAction);
    Handles.Add(Binding.GetHandle());

    // ... somewhere later ...

    for (auto Handle : Handles)
    {
        EnhancedIC->RemoveBindingByHandle(Handle);
    }
}

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.