Unreal Engine - Taking screenshots automatically

Viewed 962

I have an array of transformation matrices representing camera positions. I want to use these to take many screenshots (10s of thousands).

I want to perform this as follows:

  1. Read transform from array
  2. Place camera where it needs to be
  3. Take screenshot (automatically)
  4. Go to 1.

The blueprint I created is the following: enter image description here

Using this blueprint, unreal engine crashes, which I think is due to the loop that tries to run under 1 frame.

How to take these automatic screenshots properly?

PS: new to UE.

2 Answers

Regardless of the crashing issue, you will likely have to limit yourself to one screenshot per frame anyway, since you will want to give the renderer time to update with the new camera angle before taking the screenshot.

So I would recommend having an Index variable on your blueprint, and every frame you:

  1. Take a screenshot
  2. ++Index
  3. If Index >= CameraTransforms.Count, exit
  4. Else, set the camera to CameraTransforms[Index]

Then wait till next frame. The reason I recommend taking a screenshot first is so that you've given the game/render threads time to update the last camera transform you set at the end of the last frame.

Hope that helps! P.s. You may want to look into Sequencer, and specifically rendering out videos from it. The workflow would be roughly the same as what I outlined above, but you could skip the screenshot step and render out an image sequence instead. I don't have a full end-to-end solution for you there, just planting an idea for you to look into if you want.

You should use a reasonable delay, enough to save the file, between your calls.

Do not use a for loop, as it's resulting in a blocking call of too many operations.

Here is something that should work:

Blueprint graph

Call "start" once, then "take next" once. "Take next" is recursive, so after this, you just need to wait for needed time, until all images are made.

You might also consider using a "file exists" node, to check if the sccreenshot you're about to make already was made, and skip if it was. That way, even if you crash in the middle, you won't need to re-make all screenshots.

Related