I found a way to make it work in editor…
Inside the Widget Component OnRegister() the RegisterHitTesterWithViewport only gets called for the host viewport widget:
if ( CanReceiveHardwareInput() && bIsGameWorld )
{
TSharedPtr<SViewport> GameViewportWidget = GEngine->GetGameViewportWidget();
RegisterHitTesterWithViewport(GameViewportWidget);
}
A workaround would be to create your own Widget Component and override the OnRegister() function. You also need to register the client viewport which you can get via the GameViewportClient of the Engine ( GEngine->GameViewport). When you have this instance you can get the Viewport Widget via ClientViewport->GetGameViewportWidget();
The only thing left to do is RegisterHitTesterWithViewport.
void UMyWidgetComponent::OnRegister()
{
Super::OnRegister();
#if !UE_SERVER
if ( !IsRunningDedicatedServer() )
{
const bool bIsGameWorld = GetWorld()->IsGameWorld();
if ( Space != EWidgetSpace::Screen )
{
if ( CanReceiveHardwareInput() && bIsGameWorld )
{
if(TObjectPtr<UGameViewportClient> ClientViewport = GEngine->GameViewport)
{
TSharedPtr<SViewport> GameViewportWidget = ClientViewport->GetGameViewportWidget();
RegisterHitTesterWithViewport(GameViewportWidget);
}
}
}
}
#endif // !UE_SERVER
}
You also need to unregister it again.