Engine Version:
5.1
Repro:
- Create a clone of Lyra sample project.
- Enable Pixel Streaming Plugin
- Follow Getting Started with Pixel Streaming in Unreal Engine | Unreal Engine 5.1 Documentation
- Run the packaged project
Expected Result:
Mouse events work as expected with proper screen coordinates
Actual Results
Mouse events always map to (0, 0)
coordinates.
Root Cause
FPixelStreamingModule::StartupModule()
makes a call to FPixelStreamingModule::InitDefaultStreamer()
which tries to grab the window from SceneViewport
and call Streamer->SetTargetWindow(TargetViewport->FindWindow())
. However, the window is invalid at this point and so the screen size is calculated to be (0, 0)
in the FPixelStreamingInputHandler::ConvertFromNormalizedScreenLocation
call for all mouse events.
Workaround/Fix
Move the code block for setting the target viewport widget and window to the FStreamer::OnStreamingStarted()
call instead. Specifically the
// The PixelStreamingEditorModule handles setting video input in the editor
if (!GIsEditor)
{
// default to the scene viewport if we have a game engine
if (UGameEngine* GameEngine = Cast<UGameEngine>(GEngine))
{
TSharedPtr<FSceneViewport> TargetViewport = GameEngine->SceneViewport;
if (TargetViewport.IsValid())
{
Streamer->SetTargetViewport(TargetViewport->GetViewportWidget());
Streamer->SetTargetWindow(TargetViewport->FindWindow());
}
else
{
UE_LOG(LogPixelStreaming, Error, TEXT("Cannot set target viewport/window - target viewport is not valid."));
}
}
}
block of code.