Bind a camera actor to a monitor? (3 cameras, each for a monitor)

I have three monitors, and I have three camera actors in the game. I want to have each monitor display one of the cameras, respectively.

I already know how to get the information (id, name, resolution, etc.) about the monitors, thanks to this post FDisplayMetrics::GetDisplayMetrics | Unreal Engine Documentation

My question: Given the monitor id (or name) and the reference to a camera actor, how do I make the camera’s scene displayed on that monitor? Do I need to have three SWindow objects?

252506-cpp.png

I know a workaround: Run three game instances, each one for a camera. This is easy. Then, I use the following code to make each of them shown on corresponding monitor: Reference: https://blog.csdn.net/u014532636/article/details/80451370 (in Chinese)

#include "Misc/CommandLine.h"

void AMyActor::AA()
{
    // Move window to the corresponding monitor
    if (GEngine && GEngine->GameViewport) {

        int MonitorNumber = 1;
        FParse::Value(FCommandLine::Get(), L"monitor=", MonitorNumber);

        FDisplayMetrics Display;
        FDisplayMetrics::GetDisplayMetrics(Display);

        int8 MonitorIndex = MonitorNumber - 1;
        int32 CurrentMonitorWidth = Display.MonitorInfo[MonitorIndex].NativeWidth;
        float WidthPosition = (MonitorIndex)*Display.PrimaryDisplayWidth - CurrentMonitorWidth;
        float HeightPosition = 0.0f;

        FVector2D WindowPosition = FVector2D((-1)*WidthPosition, HeightPosition);
        GEngine->GameViewport->GetWindow()->MoveWindowTo(WindowPosition);
    }
}

Finally, add the ApplicationCore module in Build.cs file, so that the linker knows where to find the library used above.

1 Like