Okay - so I put the following code in my GameMode class:
void AMM_GameMode::Tick(float deltaTime)
{
Super::Tick(deltaTime);
if (RenderTexture != nullptr && s_TestTicks<16)
{
FCanvas canvas(RenderTexture->GameThread_GetRenderTargetResource(), NULL, 0.0f, 0.0f, 0.0f, GMaxRHIFeatureLevel);
canvas.Clear(FLinearColor(0.5f, 0.5f, 0.5f, 1.0f));
canvas.Flush_GameThread(true);
FlushRenderingCommands();
TArray<FColor> SurfData;
auto RenderTarget = RenderTexture->GameThread_GetRenderTargetResource();
RenderTarget->ReadPixels(SurfData);
UE_LOG(LogTemp, Display, TEXT("Tick: %d"), s_TestTicks);
int iToPrint = FMath::Min(4, SurfData.Num());
for (int i = 0; i < iToPrint; i++)
{
auto &c = SurfData[i];
UE_LOG(LogTemp, Display, TEXT(" {%d, %d, %d, %d}"), c.R, c.G, c.B, c.A);
}
++s_TestTicks;
}
With RenderTexture created in my constructor:
AMM_GameMode::AMM_GameMode(const class FObjectInitializer& PCIP)
: Super(PCIP)
, FontForTextItem(0)
{
HUDClass = AMM_HUD::StaticClass();
RenderTexture = PCIP.CreateDefaultSubobject<UTextureRenderTarget2D>(this, TEXT("RenderTexture"));
RenderTexture->ClearColor = FLinearColor::Black;
RenderTexture->InitAutoFormat(32, 32);
RenderTexture->UpdateResourceImmediate();
s_TestTicks = 0;
And added to my header:
UPROPERTY()
UTextureRenderTarget2D* RenderTexture = nullptr;
int s_TestTicks = 0;
And it prints different information on iOS and PC. PC is expected, iOS seems like garbage (but seemingly with a pattern to it - more so than I’ve seen in the real code).
file with example project attached - verified on PC though I have yet to get this deployed and tested on iOS.