- Home /
How to handle frame rate drop
In my project I have a lot of writing to files. I am currently working on a simulation and it is needed to extract the mesh in each frame and take screen shots in each frame and write them in file. To be more precise I create a new file for each frame, write the info I want in it and save it (using streamwriter). The simulation itself runs at 70fps. But when I start the writing part which includes the camera and the deformation of the object the frame rate drops. I wanted to know if there is a better way to handle writing to file, instead of doing it in an update method for each frame (I was thinking of threading but Unity is not thread safe).
Telling us the purpose might help us give you a better way to do this. But you can always just have an array and save the screenshots in the RA$$anonymous$$ ins$$anonymous$$d, and write them in the hard drive every second (and clear the array, of course) ins$$anonymous$$d of every frame.
The purpose is to record data for cloth deformations that is why I need the frame to frame info. I also noticed that the frame rate drops start when I, for example, start to capture the image before saving it on the HDD.
The only thing I can think of is recording it as a video. I have never done that so I can't really help there much, but this might help you http://answers.unity3d.com/questions/550280/how-to-record-a-video-runtime-and-save-it-for-play.html
I would take a snapshot of the relevant data and hand it to a class that does the writing on a second thread.
This way the main thread stays unharmed
Answer by TharosTheDragon · Nov 26, 2017 at 12:01 AM
I think there is a better way to do what you want. Maybe look into Time.captureFramerate.
Your answer
Follow this Question
Related Questions
Decompress a file with code. 2 Answers
Writing to a file which i just created. 1 Answer
It's impossible to make realistic n-body solar system simulation in matter of size and mass? 2 Answers
3d Water Simulator 1 Answer
Simulate Drag Event 0 Answers