Multiple windows and viewports and rendering multiple point of views

We are developing a library that holds and updates different states and we are using Unreal Engine to act as a renderer for the states.

I’m integrating the library inside unreal engine as a third party static library.
This library expect multiple windows and viewports to be setup and rendered.

I’m trying to examine and evaluate how I can approach this in Unreal Engine in the most efficent way.

Key Points:

  • The number of windows and viewports is arbitrary and is setup using the third party library internal configuration system
  • The rendering should be realtime and performed every frame for each view
  • The rendering should (potentially) be 100% the exact same of the “default” view (lights, shadows, postprocessing and so on)
  • I don’t care about each individual window’s input handling
  • The main default window and viewport should be handled the same way, or hidden\not rendering

What I Tried:

Using USceneCaptureComponent2D with Render Targets, drawing the Render Targets either inside a full screen UMG or using Slate:
This has a number of issues, mainly the cost of the SceneCaptureComponents and the fact that I can’t disable the “main rendering” and only keep the SceneCaptureComponents since they would stop rendering (I would have to call Capture on every Tick of the component) and I would lose all the debug rendering too (like the “stat” console commands).
Also this doesn’t address multiple windows in anyway, although I could use Slate windows for that, but still I wouldn’t be able to manipulate the main window.
Another issue with this is that it kinda mess up the Level Viewport in the editor (so far the best solution i came up with for this was a CVar to hide the UMG canvas)

Creating a custom UGameViewportClient and setup custom SplitScreen:
I tried overriding the Draw method of the UGameViewportClient class to manually setup the splitscreen views before drawing. I add a Local Player for each “view” and then manually set the origin and size of each local player view according to the library states.
The issue here is that the Origin and Size of the splitscreen views are normalized (0-1) relative to the window, while the library configuration specify the origin and size in pixels.
I could transform from pixel coordinates to normalized coordinates, but this somehow doesn’t feel right.
Also the default max local players is 4, although I’m pretty sure you can set that in a custom GameViewportClient (haven’t tried yet).

Creating a custom UGameViewportClient and manually setup the SceneViews and ViewFamly:
The idea here was to bypass the base Draw method of the GameViewportClient and implement my own Draw method and setup the SceneViews\ViewFamily much like the base method does for the split screen, but this proved to be more intricate than I thought and (also due to the lack of information\documentation regarding this) I wasn’t successful in doing this without the engine\game crashing on rendering.

Diving into the engine source code:
I compiled the engine from source and tried to modify and study the parts where the main Viewport and Window are created (in the GameEngine, GameInstance, GameViewportClient and other classes) and see if with some light modifications I could achieve what I need, but I was unsucessful again. Mostly due to me being ignorant here. I did understand a little bit better how everything is tied together by doing this, but ultimately I wasn’t able to do anything meaningful with this.

The ideal solution:
Ideally, I want to be able to create and destroy on demand a Window with one ore more Viewports and Viewpoints, including the “main” window (skipping rendering and hiding the window works too).
While it’s obvious that multiple rendering will impact performances, ideally I want to render from different point of views the same scene in the most efficent way that is humanly possible.

I’ve been on this for days now and I can’t come up with a clean and efficent solution, do you have any suggestion? I’m sure it can be done, I’ve seen plugins doing something similar.
But due to license stuff that I can’t go into right now, the use of external plugin is very limited for this project, so using those plugins is probably off the table.

Thanks in advance :pray: