Workaround for FPixelStreamingModule::StartupModule() setting invalid TargetWidow on Streamer

Engine Version:

5.1

Repro:

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.

4 Likes

But for some reason it didn’t work for me. Everything compiled, but the mouse continues to not work

1 Like

Hello! Looks like this problem in Lyra project really affect mouse input in pixel streaming.
Can’t find any fix now :frowning: Waing for update really much.

And looks like this topic is about same problem.

1 Like

Have you confirmed the window and viewport are non-null in this code when run? How are you running it? Are you on UE 5.1?

My process is to enable the “Pixel Streaming” plugin and then package a windows build and run with options like

LyraGame.exe -AudioMixer -PixelStreamingURL="ws://localhost:81" -AllowPixelStreamingCommands=true ResX=1280 ResY=720 -Unattended  -GraphicsAdapter=0  -ForceRes  -Windowed  -PixelStreamingEncoderRateControl=VBR

But most of those are not needed to get the mouse input working.

Thanx, Jacob!
I`l tried one more time and find solution. In this lines:

Streamer->SetTargetViewport(TargetViewport->GetViewportWidget());
Streamer->SetTargetWindow(TargetViewport->FindWindow());

we need change to

this->SetTargetViewport(TargetViewport->GetViewportWidget());
this->SetTargetWindow(TargetViewport->FindWindow());

Hi there can you please tell me where is the file to modify this, thanks

Well I was able to find the file, for the people like me that don’t know where is the file, this is the route

in you unreal source solution go to /Plugins/Media/PixelStreaming/Source/PixelStreamingEditor/Private/PixelStreamingEditorModule.cpp

Hi there,

Thank you for highlighting the issue and apologies for the delayed reply.
This issue has been fixed on the engine side, so the fix will be implemented in 5.2. Details are in this commit.