How to screenshot at runtime in HTML5

I’m looking for a way to create screenshots from different cameras at runtime.

Needs to run on HTML5 platform.

When I use built-in features (Execute console command (Shot, HighResShot) or GEngine->GameViewport->Viewport->ReadPixels ) the whole HTML5 Build crashes, works on native windows client.

C++ or Blueprint solutions are welcome.

Following code

FVector2D viewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY());

if (viewportSize.X <= 0 || viewportSize.Y <= 0) return;

//Section of Viewport to capture
//        entire buffer invalidated if going larger than viewport size
//        during readpixels
viewportSize.X--;
viewportSize.Y--;


ColorBuffer.Empty();

int32 viewportTotalSize = (viewportSize.X - 1) * (viewportSize.Y - 1);
ColorBuffer.AddDefaulted(viewportTotalSize);

//return;

//Get Screen Shot!
if (!GEngine->GameViewport->Viewport->ReadPixels(
	ColorBuffer,
	FReadSurfaceDataFlags(),
	FIntRect(1, 1, viewportSize.X, viewportSize.Y)

)) {
	return;
}

throws this error:

DebugBreak() called!
at FOpenGLDynamicRHI::RHIReadSurfaceData(FRHITexture*, FIntRect, TArray<FColor, FDefaultAllocator>&, FReadSurfaceDataFlags) (CSB.html:31827649:1)
at FRenderTarget::ReadPixels(TArray<FColor, FDefaultAllocator>&, FReadSurfaceDataFlags, FIntRect)::EURCMacro_ReadSurfaceCommand::DoTask(ENamedThreads::Type, TRefCountPtr const&) (CSB.html:13016631:1)
at FRenderTarget::ReadPixels(TArray<FColor, FDefaultAllocator>&, FReadSurfaceDataFlags, FIntRect) (CSB.html:13015336:1)
at AMyScreenshotActor::TakeScreenshot(FString) (CSB.html:803215:1)
at AMyScreenshotActor::execTakeScreenshot(FFrame&, void*) (CSB.html:827004:1)

Hello,

We’ve recently made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

https://forums.unrealengine.com/unreal-engine/announcements-and-releases/1410408-unreal-engine-bug-submission-form

Thanks

Did you find a solution?

Yes

use a screencapture2D component, make a c++ function where you create the texture at runtime and check the format of the texture carefully - rgba8 (float8, instead of 16)

and do not compress it as a png, I suggest you read the FColor Array from ReadPixels() and put it into a uint8 * 3 (rgb) array for further process

bump here, I am looking for the same. I tried with the blueprint execute console command. But it’s not working