Hi, I am trying to take a screen shot within magic leap. By debugging, I am sure that I have already reach the line of ScreenCapture.CaptureScreenshot(filePath), and the folder was created. However, after execution of the app, there was no picture saved in the folder. Here is the code:
I recommend adding additional debug statements, then checking the logs to see if the script completes successfully by reading the logs. You should also check if you are running into any errors.
These lines in my code are for debug printing. They both printed out.
Is that sufficient to prove the ScreenCapture.CaptureScreenshot(filePath); is already called successfully? Meanwhile, I also used debug print to check and show that the filePath is exist.
For the log, do you mean by the log in Device bridge?
Printing out the file location might help you locate where is it being saved on device. Additionally, you can capture the logs via ADB or device bridge through the Magic Leap Hub. You can also use the Unity ADB log cat package.
Hi, I tried but they are not work. The CaptureScreenshot didn't give any error output. Is that possible that some Magic Leap setting that disable saving images?
Magic Leap does not limit saving files outside of the standard constraints of Android. To further diagnose, do you mind conducting a file write test? This will pinpoint whether the issue is with the Unity screenshot functionality or broader file writing permissions on Magic Leap 2.
Implement this method and call it under the same conditions as your screenshot capture. If the test file is successfully written but screenshots still fail, this indicates a potential issue with Unity's screenshot mechanism. If the test file also fails, this points to broader file access issues in your application.
When Using the following script in the latest Unity magic Leap Examples resulted in a screenshot without any issues. Make sure you request storage permissions
using System.Collections;
using UnityEngine;
public class ScreenshotTest : MonoBehaviour
{
// Call this method to take a screenshot and save it to local app storage
public void Start()
{
StartCoroutine(CaptureScreenshotCoroutine());
}
private IEnumerator CaptureScreenshotCoroutine()
{
yield return new WaitForSeconds(3);
// Define the filename and path for the screenshot
string screenshotFilename = "screenshot.png";
string screenshotPath = Application.persistentDataPath + "/" + screenshotFilename;
// Capture the screenshot
ScreenCapture.CaptureScreenshot(screenshotFilename);
// Wait for the end of the frame to ensure the screenshot has been captured
yield return new WaitForEndOfFrame();
// Optionally, output the screenshot path to the console
Debug.Log("Screenshot saved to: " + screenshotPath);
}
}
Hi, I have tested your code on both my project and the magic leap example 1.20 (my project is build under similar environment of magic leap example1.20) And although the image was saved successfully, it only has a small pixel. (like below graph)
However, this code works perfectly with magic leap example 2.0. (like below graph)
What's different in the projects lead to this different performance? Is that because the different unity version used by these projects? (1.20 use unity 2022.2.0.f1 and 2.0 using 20223.11.f1)
Hi, after I force switch the unity version to 3.11f1, the screen shot works but my webview rendering page no longer works. The whole WebViewScreen just disappear and even without the white panel at first. But when I compile the whole project again, it works perfectly. Thank you!