Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by bhayward_incrowd · Feb 25, 2016 at 04:43 PM · functionpauseframeratewrite dataexecution

How to pause execution until function terminates

I am writing a game/program which every few seconds has to write a lot of data to the hard disk - this takes a few seconds to complete, and naturally causes the game to hang for that duration.

However, when the game resumes after the writes have completed, the game skips a few frames.

I need it that Unity will skip absolutely no frames what so ever. How can I force the Unity Engine to stop executing until the writing has fully completed, so that when it resumes, no frames have been skipped?


Context:

To provide some context, I am capturing a screenshot every frame, storing them as Texture2Ds in a queue. When the queue has more than 100 frames worth of Texture2Ds in it, I am writing the to the disk as PNGs, and clearing the queue.

I want to pause rendering/execution whilst the writing takes place so that the output (alone) is seamless.

Comment
Add comment · Show 2
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 hexagonius · Feb 25, 2016 at 05:43 PM 1
Share

The engine does not skip frames. it's just that the time runs on and every time dependent task is jumping by that large delta time. I think you can do one of the following:

  • create a class or coroutine you pass your bundle in that writes them one or two or three at a time

  • create another thread doing the writing

  • have your own time variable everything depends on that does not get increased by the full delta time when writing files

thinking about it, I'd do the threading

avatar image bhayward_incrowd hexagonius · Feb 26, 2016 at 11:43 AM 0
Share

hexagonius, this was a great reply, thank you. In the end, I have implemented a coroutine for writing every frame. Unity handily has Time.captureFramerate, which is perfect for preventing the game from advancing until the write has finished.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by StardustMotion · Dec 14, 2020 at 12:18 PM

@bhayward_incrowd I believe I had the same problem as you and found a workaround. For my personal project, I had to screenshot a high quality (~2048x4096 pixels) 360° view of the player's camera at least 30 times/second in order to make a Unity 360° video. That's very expensive and impossible to produce in real-time on my computer. So Unity freezes while writing the screenshot, and resumes then, with some frames skipped...

To fix this : Edit > Project Settings > Time And set "Maximum allowed timestep" to the same value as Fixed Timestep. What Maximum allowed timestep does is that, when your FPS becomes so garbage that you can't render every frame without having a smooth experience, Unity will skip some frames instead, depending on "Maximum allowed timestep" value.

If, like me, you need to collect every single frame, at the cost of a very slow game (x0.1-ish), proceed as above. For making pre-rendered videos, where quality > game speed it's great.

For actually interactive video games, it's bad ; you're better off with 1.0x speed and skip some frames.

Comment
Add comment · 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

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

48 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding to a text file. It works but I get this message afterwoods 1 Answer

Pausing the game after player gets destroyed 1 Answer

Issues Pausing My App 1 Answer

Does framerate affect Coroutines? 1 Answer

What to do for many comparison operations in foreach loop? 0 Answers


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