Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by saruul34 · Mar 15, 2014 at 11:52 AM · iosperformanceframerate drops

CaptureScreenshot

Hello, I have a little performance problem with Application.CaptureScreenshot function. It's 2D scrolling game for IOS. When the player dies, I capture screen by CaptureScreenshot. But it drops half of the FPS and lags. (from 60 to (30~45)).

Without capturing screenshot, FPS doesn't drop and the game hasn't got any lag.

I have tried to reduce hitches by lerping timescale to 0.5. It improves little bit but not quite enough.

Does anyone know best way to take a screenshot? Thanks in advance.

Comment
Add comment · Show 6
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 $$anonymous$$ · Mar 15, 2014 at 01:15 PM 1
Share

Sadly Application.CaptureScreenshot will peak on your performance. The only other alternative I know is to use EncodeToPNG as described here:

http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html

Or if you have pro to use a render texture.

avatar image saruul34 · Mar 15, 2014 at 03:28 PM 0
Share

Ty for your reply. I will do test both of them on $$anonymous$$onday.

avatar image saruul34 · Mar 17, 2014 at 07:14 AM 0
Share

I have tested http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.EncodeToPNG.html But it's even worse, decreasing FPS to 20 ~ 25.

 private IEnumerator TakeScreenshot() {
         yield return new WaitForEndOfFrame();
         
         var width = Screen.width;
         var height = Screen.height;
         var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
         // Read screen contents into the texture
         tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
         tex.Apply();
         byte[] screenshot = tex.EncodeToPNG();
         Destroy(tex);
 
         File.WriteAllBytes( Application.persistentDataPath + "/" + screenshotFilename + ".png", screenshot);
     }
avatar image saruul34 · Mar 18, 2014 at 06:22 AM 0
Share

Also I have tried with threading with File.WriteAllBytes but no luck.

Is there any method that saves the current camera render to memory. After that I can save to file.(Some moment later.)

avatar image $$anonymous$$ · Mar 18, 2014 at 11:22 AM 1
Share

Sorry for the late reply. As far as I know the only way to save a camera render apart Application.CaptureScreenshot is with a RenderTexture, sadly I can't help you here as I haven't the pro version of unity, which is required for RenderTexture.

But with some research on the forums I think you can find info on this.

Show more comments

1 Reply

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

Answer by saruul34 · Mar 19, 2014 at 08:03 AM

Thank you @Neurological for keep helping me. I have solved this question by RenderTexture as you adviced.

  1. Assets -> Create -> Render Texture

  2. public RenderTexture currentRT; // Drag here created texture.

  3. Called when the player dies:

    private IEnumerator TakeScreenshot() {
            yield return new WaitForEndOfFrame();
            Camera.main.targetTexture = currentRT;
            yield return new WaitForSeconds(0.2f);
            Camera.main.targetTexture = null;
        }
  1. When screenshot needed, save to Document

 void save () {
     int width = 512;
     int height = 256;
     Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
         
         // Read screen contents into the texture
         RenderTexture.active = ScreenShot.Instance.currentRT;
         tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
         tex.Apply();
         byte[] screenshot = tex.EncodeToPNG();
         RenderTexture.active = null;
         File.WriteAllBytes(pathToImage, screenshot);
     }

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 $$anonymous$$ · Mar 19, 2014 at 10:49 AM 0
Share

Glad you solved it, and thanks for posting your solution, if one day I'll be able to get a Pro license I'll be sure to follow your solution.

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Profiler does not show objects when hooked to an iPad 1 Answer

Bad iOS Performance after good android build. 2 Answers

Best Practice For Shader Complexity + IOS 1 Answer

How to perform intersection test between two colliders? 2 Answers

Performance woe - full log given 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