0
\$\begingroup\$

I record object data (position,rotation) for objects in a scene and store it to a file. At some stage the player can load this file and "play back" the recording to watch themselves. Obviously they can now have a different view. As its trivial to store each frame to a png and then stitch them together as an movie file, I decided to add an export function.

The png sequence is rendered to have 60FPS at the best quality as the render fps does not really matter anymore.

The problem :

Everything else in the scene (clouds/vegetation) is still based on Time.deltaTime. Because it takes much longer to render at ultra and store to an PNG, Time.deltaTime is way off my 60FPS the objects are rendering at. (if that makes sense).

Basically if I render 600 frames, the objects moved for 10 seconds. But everything else moved for the entire render time of 600 frames that will be like 20 seconds. So the backgound looks to be in fast forward.

The question

Is there anyway to set Time.detaTime manually or trick the Unity into setting Time.deltaTime to 1/60 ? Then all the other assets will be in sync with the set FPS and render ?

Ideas

  • If I had access to all the assets (including Unit's vegetation) I could hack the code to use a defined time step.
  • Not sure if there is some trick with VSync that could help.

Like I said, I am not sure that this can even be done. Any suggestions will be welcome.

\$\endgroup\$
3
  • \$\begingroup\$ Have you considered using Time.timeScale? \$\endgroup\$
    – DMGregory
    Commented Oct 23, 2021 at 21:55
  • \$\begingroup\$ @DMGregory I have used Time.timeScale before and know that it only affects the physics 'time scale. \$\endgroup\$ Commented Oct 25, 2021 at 8:52
  • 1
    \$\begingroup\$ That's false, but Acme Nerd Game's answer below is better anyway. 😉 \$\endgroup\$
    – DMGregory
    Commented Oct 25, 2021 at 9:37

1 Answer 1

2
\$\begingroup\$

Time.captureDeltaTime is provided specifically for this purpose — capturing screenshots between frames.

If this property has a non-zero value then Time.time increases at an interval of captureDeltaTime (scaled by Time.timeScale) regardless of real time and the duration of a frame. This is useful if you want to capture a movie where you need a constant frame rate and want to leave enough time between frames to save screen images.

\$\endgroup\$
2
  • \$\begingroup\$ I feel really dumb now. I am not sure how I missed it. Thank you. \$\endgroup\$ Commented Oct 24, 2021 at 17:17
  • \$\begingroup\$ Lol. Nah -- we're all learning. \$\endgroup\$ Commented Oct 24, 2021 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .