Hi guys,
So I am currently looking into a feature that’s required for a project, specifically, I have three separate cameras setup in my Player blueprint, and I need all three of them to render to separate views. Each of these views will be fit on a separate monitor, or projected by three separate projectors, based off client requirements.
I have been able to setup my character with three cameras (which honestly is the easiest part of the deal), but where I’m getting stuck is creating three different viewports for these three separate cameras. I tried looking into a previous thread and tried to make some sense of it, but honestly, I find it slightly cryptic:
https://answers.unrealengine.com/questions/30918/does-ue4-support-multiple-monitors.html
More specifically, I am alluding to the section where Mike is talking about the UGameEngine::Init() and the CreateGameWindow and CreateGameViewport methods.
Hunting around a bit more, I found the wiki page for how to override the UGameEngine module:
Following the methods described here, I have been able to successfully subclass the UGameEngine class into my own class called CTGameEngine. And that’s about all that I’ve been able to do.
I tried setting up my own viewport, but I always end up with an exception. Here’s the offending code:
void UCTGameEngine::Init(IEngineLoop * InEngineLoop)
{
DECLARE_SCOPE_CYCLE_COUNTER(TEXT("UGameEngine Init"), STAT_GameEngineStartup, STATGROUP_LoadTime);
// Call base.
UGameEngine::Init(InEngineLoop);
// Creates the initial world context. For GameEngine, this should be the only WorldContext that ever gets created.
FWorldContext &InitialWorldContext = CreateNewWorldContext(EWorldType::Game);
// Initialize the viewport client.
UGameViewportClient* ViewportClient2 = NULL;
if (GIsClient)
{
ViewportClient2 = ConstructObject<UGameViewportClient>(GameViewportClientClass, this);
ViewportClient2->SetReferenceToWorldContext(InitialWorldContext);
GameViewport = ViewportClient2;
InitialWorldContext.GameViewport = ViewportClient2;
SecondaryViewportClients.Add(ViewportClient2);
}
if (ViewportClient2)
{
ViewportClient2->AddToRoot();
ViewportClient2->LayoutPlayers();
//ViewportClient2->SetViewport();
CreateGameViewport(ViewportClient2);
}
bIsInitialized = true;
}
This is almost a straight lift from the UGameEngine::Init() documentation.
When I tried to debug it, I found that my ViewportClient2 was a NULL pointer, even though it was actually going through all the steps of creating the ConstructObject, etc.
So, any pointers (pun not intended) on what I may be doing wrong here? And what I should be trying to do instead (other than asking someone else to look into coding this thing, that is not an option)?