Android AR Screenshot Needle 4.0

Regarding the Android AR screenshot, I am getting a black screen instead of the camera feed.
I am using this code:

const res = screenshot2({
            type: "blob"
        }).then(blob => {
            if (blob) {
                const file = new File([blob], "screenshot.png", { type: "image/png" });
                navigator.share({
                    title: "Samsung TV",
                    text: "Holofiction WebAR Showcase!",
                    files: [file],
                });
            }
        })

Hi Tomislav,

It seems that the issue with the black screen instead of capturing a screenshot from the AR session might be related to missing XR feature requirements in your Needle Engine setup. To properly capture a screenshot in an AR session in Needle Engine, it is essential to request the camera access XR feature. You can achieve this by ensuring the following:

  1. WebARCameraBackground Component: Add the WebARCameraBackground component to your scene or specify camera permissions in your session request setup (see the documentation).

  2. Ensure XR Session Configuration: Verify that your XR session is properly initialized with the necessary permissions, including camera access. This can typically be done in the NeedleXRSession.onSessionRequestStart event hook (see the documentation).

  3. Correct Usage of screenshot2: Your code calls the screenshot2 with options, which is appropriate, but ensure that the rendering setup allows for XR images to be captured correctly. If screenshot2 is delayed until the correct rendering frame is captured, then it should work correctly (see the documentation) (see the documentation).

To better troubleshoot this issue, make sure you have configured the Needle Engine settings to allow camera access during XR sessions. If you already have this setup, please check if there are any console warnings or errors when running your project. These can give more insights into what might be going wrong.

If you are still having issues, please provide additional details on how your AR session is set up, or consider checking the logs for any XR session-specific errors.

For more details and the latest API references, you may also explore the Needle Engine documentation and WebXR specifications.

If you need further assistance or details, feel free to reach out!

24 replies left
thread_Wg5hCZR2E4J6NHmhIcuVyt3I
Reply to this message to continue the conversation

Looking into it

You need to request camera-access. There’s a log in the console (you should see it when you exit AR).

Add this to your main.ts in your project for example to request the camera feed:

NeedleXRSession.onSessionRequestStart(evt => {
    evt.init.optionalFeatures = evt.init.optionalFeatures || [];
    evt.init.optionalFeatures.push('camera-access');
});

That will fix the issue

1 Like

Now it works but I got a strange camera feed in my UI texture,

Are those UI Image components? And does this happen right away or just after taking a screenshot?

Could you send this as a bugreport?
We noticed some strange behaviour in three.js once camera-access is requested elsewhere (even without ever using it at all) but are still investigating - so it might also be an issue in three. I haven’t seen something like this yet tho so it would be great to get your scene for testing.

It happens as soon I open WebXR, but not on all textures, as you can see the screenshot button is not affected.
Do you want me to share a project with you or just a scene file?

Use the bugreporter please (Needle Engine/Report a bug).
I tried to reproduce it here without luck.

I have sent Bug report

One more question, when I share the screen, my Canvas items are not shared, so if I want to add some watermark or logo it is not shared, is there a way to share canvas items also?

By canvas items you mean UI setup in Unity or do you mean HTML UI that sits ontop of the webgl canvas / element?

I mean UI setup in Unity

Ah I see, I’ll double check that, if it’s screenspace UI it may indeed not be part of the screenshot right now since that is rendered in a separate render pass. Will get back to you.

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.