Tree Shaking Tools Breaking

When I try import { CreateScreenshotAsync } from "@babylonjs/core/Misc/screenshotTools"; my code breaks. I am just using it like this:

const data = await CreateScreenshotAsync(
engine,
scene.activeCamera as Camera,
150,
);

This works fine when I import Tools, but stops working when I try the tree shaking way. Is there a way to fix this without having to import Tools from core?

You need to import:

CreateScreenshot, CreateScreenshotUsingRenderTarget , EncodeScreenshotCanvasData as well.

CreateScreenshotAsync is just an async wrapper.

Check the log which function is missing if it still doesn’t work. Maybe there are more side effects. You need to import all functions used in the screenshot process.

I am not getting errors or warnings in the logs.

I also attempted import { ScreenshotTools } from "@babylonjs/core/Misc/screenshotTools"; alongside import "@babylonjs/core/Misc/tools"; which also doesn’t work.

You don’t even need to import anything else just this:

import { CreateScreenshotAsync } from "@babylonjs/core/Misc/screenshotTools";

This creates a screenshot:

        scene.onReadyObservable.addOnce(async () => {
            const base64 = await CreateScreenshotAsync(engine, camera, {
                width: 1024,
                height: 1024,
            });
            console.log(base64);
        });

base64:

can you share a repro ?

Turns out I was missing some side effect imports for my other imports, but now it works expected after importing those.