Hello all,
I have created a hook in C++ which intercepts all input events in an UMG menu for the purpose of handling key binding assignments.
When the UMG menu initializes I want to register an event handler in defined in Blue Print, which is essentially invoked for every key press (from C++).
I observe that in UGwGameInputManager::RegisterKeyDownInputPreProcessor the handler is bound to the widget where the event handler (HandleKeyDown) is defined. However when a key is pressed and GwInputInterceptor::HandleKeyDownEvent is executed, the KeyDownHandler is unbound. (in all this time the widget is alive)
Can anyone help understand what happens? Does HandleKeyDown go out of scope from the blueprint?
Kind regards,
Definition of the dynamic delegate type (later used in Blueprint):
UCLASS()
class PROIECT12_API UGwGameInputManager : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
DECLARE_DYNAMIC_DELEGATE_OneParam(FHandleKeyDown, const FInputEventArgs&, InOutInputEventArgs);
UFUNCTION(BlueprintCallable)
static void RegisterKeyDownInputPreProcessor(const FHandleKeyDown& handler);
};
Referencing and invokation of the delegate:
class GwInputInterceptor : public IInputProcessor
{
private:
TSharedPtr<const UGwGameInputManager::FHandleKeyDown> KeyDownHandler;
public:
virtual void Tick(const float DeltaTime, FSlateApplication& SlateApp, TSharedRef<ICursor> Cursor)
{
}
bool HandleKeyDownEvent(FSlateApplication& SlateApp, const FKeyEvent& InKeyEvent)
{
if (KeyDownHandler.IsValid() && KeyDownHandler->IsBound()) {
FInputEventArgs args;
args.InKeyEvent = InKeyEvent;
args.OutHandled = false;
KeyDownHandler->Execute(args);
return args.OutHandled;
}
return false;
}
GwInputInterceptor(TSharedPtr<const UGwGameInputManager::FHandleKeyDown> KeyDownHandler)
{
this->KeyDownHandler = KeyDownHandler;
}
};
void UGwGameInputManager::RegisterKeyDownInputPreProcessor(const FHandleKeyDown& handler)
{
FSlateApplication& CurrentSlateApplication = FSlateApplication::Get();
GwInputInterceptor* interceptor = new GwInputInterceptor(TSharedPtr<const UGwGameInputManager::FHandleKeyDown>(&handler));
CurrentSlateApplication.RegisterInputPreProcessor(TSharedPtr<IInputProcessor>(interceptor));
}
Definition of the Event handler which is further delegated:
