Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by AstrobearGames · Aug 09, 2016 at 02:40 PM · unity 5editorapplicationscreenshot

Can't capture Multiple Screenshots in one Second

Hey

I am having trouble saving Multiple Screenshots really fast in Unity using Application.CaptureScreenshot

It appears that the Capture Screenshot function is only saving out one file per second

It is reporting multiple inputs second and each of them have a different filename so to avoid overwriting the previous screenshots. However Unity only seems to be saving the last screenshot recorded in that second.

It is not exactly needed to save them this fast, but it would be nice to figure out how to make this work in the event I ever do need to have them saved quickly.

Code:

 public static class ScreenshotHelper
 {
     static DateTime m_LastTime = new DateTime(0);
     static int m_LastNumber = 0;
 
     [MenuItem("Tools/Save Screenshot &P")]
     public static void TakeScreenshot()
     {
         if (m_LastTime.Approximately(DateTime.Now)) { m_LastNumber++; } else { m_LastTime = DateTime.Now; m_LastNumber = 0; }
 
         string t_Filename = Application.productName + " - " + m_LastTime.ToString("yyyy-MM-dd HH-mm-ss");
         if (m_LastNumber != 0) { t_Filename = t_Filename + " (" + m_LastNumber + ")"; } 
 
         string t_FilePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + t_Filename + ".png";
 
         Debug.Log("Screenshot Saved to \"" + t_FilePath + "\"");
         Application.CaptureScreenshot(t_FilePath);
     }
 
     static bool Approximately(this DateTime a_Self, DateTime a_CompareTo)
     {
         if (a_Self.Year != a_CompareTo.Year)        { return false; }
         if (a_Self.Month != a_CompareTo.Month)        { return false; }
         if (a_Self.Day != a_CompareTo.Day)            { return false; }
         if (a_Self.Hour != a_CompareTo.Hour)        { return false; }
         if (a_Self.Minute != a_CompareTo.Minute)    { return false; }
         if (a_Self.Second != a_CompareTo.Second)    { return false; }
 
         return true;
     }
 }

Debug Log Output: alt text

Actual File Output: alt text

example-debugoutput.png (49.7 kB)
example-fileoutput.png (21.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Yujingping · Aug 09, 2016 at 06:18 PM

Hi there. I have successfully reproduced your issue in Unity 5.4.0f3 and the response is exactly what you have described. Perhaps this is a bug or so and lets consider reporting it to the official. However just to solve your problem, I think you may try ReadPixels which allows you to dynamically control the parameters of the screenshot. Here is my example code:

 private IEnumerator TakeScreenshot ()
     {
         yield return new WaitForEndOfFrame ();
         Texture2D screenShot = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
         screenShot.ReadPixels (new Rect (0, 0, Screen.width, Screen.height), 0, 0);
         screenShot.Apply ();
         byte[] bytes = screenShot.EncodeToPNG ();
         int index = ImageNumber + 1;
         ImageNumber++;
         string fileName = Application.persistentDataPath + "/Screenshot" + index + ".png";
         System.IO.File.WriteAllBytes (fileName, bytes);
     }

I have tried this and it works pretty fine. Please note that don't miss "yield return new WaitForEndOfFrame ();" at the first line in the Coroutine. Otherwise it may not work as predicted. Do not take screenshots too frequently on mobile platforms. I have experienced crash when doing so. Also please note that if you wanna to control the size, you may compress the PNG file by "screenShot.Compress ();". However this does not work on iOS for some unknown reason. If you have further questions please feel free to contact me. GL & HF!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AstrobearGames · Aug 10, 2016 at 04:47 AM 0
Share

This worked great for me, except for the fact that it requires to be on a monobehaviour for the coroutine to work.

Here is my final version I came up with Here on GitHub Gist

For anyone who happens to come across this, it works on PC fine, might need some tweaking for other keyboard layouts and/or platforms

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity mainmenu audio problem. 1 Answer

Unity not recognizing clipboard contents (Still Unsolved) 1 Answer

Applying material to compound prefab 0 Answers

Why doesn't Application.CaptureScreenshot work in Windows player? 1 Answer

Take photo in unity 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges