Can i perform InputController->BindAction with a Dynamic Delegate?

Hi, i want to experiment a good way to handle input functions dynamically, and i thougth using dynamic delegate binding would be a nice idea, however my idea seems not working.
i want to setup input into my PlayerController’s SetupInputComponent, by binding actions with BindAction, but putting a dynamic delegate instead of a function, in order to call whichever function i bind into my delegate instance. i see that this does not work. can someone help me get rid of this problem somehow? Here’ a code sample below:
(the two “Change” functions simply unbind the delegate and bind with another void function)
DECLARE_DYNAMIC_DELEGATE(FCustomCommand) ← <- (my dynamic delegate)
void AMyPlayerController::SetupInputComponent()
InputComponent->BindAction(“CurrentCommand”, IE_Pressed, this, &AMyPlayerController::Command); ← <- (Here’s my problem! Command is a variable)
InputComponent->BindAction(“ChangeCommand A”, IE_Pressed, this, &AMyPlayerController::ChangeA);
InputComponent->BindAction(“ChangeCommand B”, IE_Pressed, this, &AMyPlayerController::ChangeB);


No, but you can bind a function or lambda that then broadcasts a member delegate.

1 Like

The input system is already dynamic and can be adjusted at runtime, so unless you need multicast for some reason, why duplicate the work?

1 Like

well, i though that SetupInputComponent is called once, so how can i dynamically bind and unbind at runtime? I mean, i could call BindAction whenever i need it, and i’m experimenting that right now, and thrown that Command delegate away, but there’s another problem. It is difficult to unbind the current action and rebind it with a new one. i’m trying to use RemoveActionBinding and others, but there’s no point this system wanna work. what should i do? maybe FInputActionBinding and FInputActionHandlerSignature could be helpful?

SetupInputComponent is just a nice clean way to add input binds when the actor is created. You don’t need to do it there. You just need to get access to the InputComponent. Now yes, removing a bind is slightly more painful. You’ll need to grab the bind’s handle that is returned in the FInputAxisBinding struct and store it off somewhere so you can use RemoveActionBindingForHandle().