Render target and pixel format

Can a UTextureRenderTarget2D have any pixel format other than the default “PF_FloatRGBA” when used with a USceneCaptureComponent2D source?

These are defined in te header file:

USceneCaptureComponent2D *Camera;
UTextureRenderTarget2D *RenderTarget;

Then in the Actor class definition:

Camera = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT(“Camera”));
RenderTarget = NewObject<UTextureRenderTarget2D>();
RenderTarget->InitAutoFormat(512, 512);
Camera->TextureTarget = RenderTarget;

Above compiles no problem but…

Camera = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT(“Camera”));
RenderTarget = NewObject<UTextureRenderTarget2D>();
RenderTarget->InitAutoFormat(512, 512);
RenderTarget->OverrideFormat = EPixelFormat::PF_A8R8G8B8;
Camera->TextureTarget = RenderTarget;

Crashes the editor.

Is there a way to configure this correctly?

Thanks for any help!

I’m using render targets with capture components like this:



    UTextureRenderTarget2D* RenderTarget = NewObject<UTextureRenderTarget2D>();

    RenderTarget->RenderTargetFormat = ETextureRenderTargetFormat::RTF_RGBA8;
    RenderTarget->Filter = Filter;

    RenderTarget->InitAutoFormat(Size.X, Size.Y);
    RenderTarget->UpdateResourceImmediate(true);

    ...


    SceneCapture->TextureTarget = RenderTarget;
    SceneCapture->CaptureScene();


You can probably leave out the UpdateResourceImmediate if you aren’t going to manually capture immediately, but the format definitely has to be set before you call InitAutoFormat.

That helps thanks. Though there are fewer ETextureRenderTargetFormats to choose from.