Optimizing Frame Rate - Saving Screenshot

Optimizing Frame Rate - Saving Screenshot

Today I had an interesting issue while serializing data.

This issue came about while working on SuperStickGame saving functionality. I couldn't find out why when the hero crossed a trigger collider which then execute a call to serialize my level and save it out to a file caused incredible spikes in FPS during the game, making it look very very bad. So what I decided to do is change the way I was calling Application.CaptureScreenshot and instead of trying to fight with IO and heavy writes, I used a very helpful property called Time.captureFramerate which made the frames per second during the file saved be static and then when I finished generating a screenshot it was set back to 0 which resets back.

Here's a sample code I leave you guys in case you are interested in knowing how I coded it the solution:

Code Snippet


Thank you for your time and don't forget to subscribe to my newsletter, also be sure to find me at @dilmerv and stop by and say hi as I love to chat with everyone.

Pingbacks are closed.

  1. Mihai Paraschivescu Mihai Paraschivescu on 03/29/2017 12:20 a.m. #

    Nice solution, but in the same time that's an ancient way of dealing with asynchronous calls (ie yield + IEnumerator). I wonder if you can't use C#'s async/await with Task mechanism in Unity. That's the proper way of doing it since C# 5.0

    Btw, nice blog! I will definitely check it periodically :)

  2. Dilmer Valecillos Dilmer Valecillos on 03/29/2017 3:02 a.m. #

    I agree Mihai, the main reason I used the yield + iEnumerator was due to not having anything greater than .NET 2.0 subset in Unity 5.5 as they've been stock with the CLR 2.0 for a while, however I know Unity has been working on offering .NET 5.0 but nothing yet.

    You can find more information about their plans on this link


Post your comment