I have a UMG blueprint parented to a custom c++ class which in turn is parented to UUserWidget. I need my c++ class to receive KeyDown events. I tried to do an override, but it’s not working. Is it possible for a UMG BP or its parent to get KeyDown events?
Just to check the basics first, when overriding, you used the BlueprintNativeImplementation function, like so?
virtual FEventReply OnKeyDown_Implementation( FGeometry MyGeometry, FKeyboardEvent InKeyboardEvent ) override;
If that doesn’t work, there are lots of factors that could be causing it. It could be because your widget blueprint doesn’t have keyboard focus, or another widget up the hierarchy is handling the event.
Make sure the widget’s bSupportsKeyboardFocus is true (the default). You might have to call SetKeyboardFocus on the widget manually, but Slate (and therefore UMG) is generally smart about this.
Also, make sure your input mode isn’t GameOnly (through APlayerController::SetInputMode), as this is usually for HUDs or other UIs you never want to interact with.
BlueprintNativeImplementation doesn’t like a virtual tag on the declaration.
I meant the BlueprintNativeImplementation generated function, missed a word there. BlueprintNativeImplementation UFunctions autogenerate a corresponding C++ declaration with the _Implementation suffix. This is the function that is called if you don’t have a Blueprint implementation and therefore the function you want to override. Basically as in my code snippet.
(If you do have a Blueprint implementation, you can still call the generated C++ function by right clicking the Blueprint implementation and choosing “Add call to parent function”.)