July 30, 2015, 12:29pm
I’m trying to get a native texture pointer to the content currently displayed on screen.
Using 4.8.3 and executing the following code on the render thread:
Returns the correct texture pointer when run in the editor, and everything works fine.
However, when I run my project as a standalone or after packaging, it returns a null pointer. I’m guessing the viewports and rendertargets are set up differently in standalone mode compared to regular mode. How can I achieve what I want, so it works in all cases?
August 3, 2015, 2:07pm
Okay, so I managed to get non-null texture pointer, by moving the code to the Draw() method of a custom UGameViewportClient, but the texture I get is not being rendered to when playing as standalone (I get a completely black texture). The exact same code works fine in PIE-mode.
August 4, 2015, 1:41pm
So it seems that the viewport in PIE-mode creates a render texture with a format that is different from the one in standalone mode. I get:
PF_B8G8R8A8 in PIE-mode
PF_A2B10G10R10 in standalone-mode
Can I force the render texture format of standalone mode to be the same format?
Did you get anywhere with this?
I’m trying to enable the AVIWriter::StartCapture during a standalone build. Of course it gets a viewport with a null RenderTarget…
November 19, 2015, 10:37pm
Hey Yu He!
I am working on a similar issue and like you can only get black video out. Did you end up finding a way to convert the Pixel Format?
Information on this stuff is so hard to find >.<
November 26, 2015, 3:15pm
I did in fact solve this! To convert the pixel format, you can sample the backbuffer using a simple pixel shader and draw it on a new render target with the desired size and format. Seems to have close to zero impact on performance.
February 19, 2019, 10:51am
hi Ye Hu, can you give some light on how did you solve this? Thanks alot, i’m having the same issue
Similarly to Madlions, I was wondering if you could shed some more light on how you managed to get the texture from the viewport in standalone mode?
November 26, 2022, 11:35pm
I use RTF_RGB10A2 in PIE mode, works perfectly. Where did you get that it’s PF_B8G8R8A8 in PIE?
November 27, 2022, 3:57am
Ok, i made it work SOMEHOW.
class SCENARIOSYSTEM_API URQ_GameViewportClient : public UGameViewportClient
virtual void Draw(FViewport* InViewport, FCanvas* Canvas) override;
void CopyViewportToRenderTarget(UTextureRenderTarget2D* RenderTarget);
void CopyTextureRHI(FRenderTarget* MyViewRenderTarget, UTextureRenderTarget2D* DestRenderTarget);
and .cpp file:
void URQ_GameViewportClient::Draw(FViewport* InViewport, FCanvas* Canvas)
if (InViewport && PendingCopyViewportToRenderTarget)
void URQ_GameViewportClient::CopyViewportToRenderTarget(UTextureRenderTarget2D* RenderTarget)
MyRenderTarget = RenderTarget;
PendingCopyViewportToRenderTarget = true;
void URQ_GameViewportClient::CopyTextureRHI(FRenderTarget* MyViewRenderTarget, UTextureRenderTarget2D* DestRenderTarget)
[MyViewRenderTarget, DestRenderTarget](FRHICommandListImmediate& RHICmdList)
FTexture2DRHIRef destTexture = DestRenderTarget->GetRenderTargetResource()->GetRenderTargetTexture();
RHICmdList.CopyToResolveTarget(MyViewRenderTarget->GetRenderTargetTexture(), destTexture, ResolveParams);
This this custom viewoirt client, so don’t forget to tell UE5 to use it in DefaultEngine.ini:
RenderTarget2D is using RTF_RGB10A2 pixel format