Download

How to wait for take_high_res_screenshot?

I have a script that takes a screenshot using


screenshotTask = unreal.AutomationLibrary.take_high_res_screenshot(SCREEN_X, SCREEN_Y, screenshotPath)

How do I wait for screenshotTask.is_task_done() to become true?

Think the file should be accessible the very next line, the limitation I found is mostly that you can only make one capture this frame. We implemented something like a ‘coroutine’ in our python bridge a function that would allow us to in python yield result per frame,


for x in range(10):
  # capture screen, and edit settings for next frame, 
  yield WaitForNextFrame

I noticed that on_tick waits for texture streaming causing hiccups and skips a few screenshots, but pre_tick does the work here is updated version




import unreal


class capture(object):
  def __init__(self):
    unreal.EditorLevelLibrary.editor_set_game_view(True)
    self.actors = (actor for actor in unreal.EditorLevelLibrary.get_selected_level_actors())
    self.on_pre_tick = unreal.register_slate_pre_tick_callback(self.__pretick__)

  def __pretick__(self, deltatime):
    try:
      actor = next(self.preactors)
      shot_name = actor.get_name()
      unreal.EditorLevelLibrary.pilot_level_actor(actor)
      unreal.AutomationLibrary.take_high_res_screenshot(1920,1080, shot_name + ".png")
      unreal.EditorLevelLibrary.eject_pilot_level_actor()
    except Exception as error:
      print(error)
      unreal.unregister_slate_pre_tick_callback(self.on_pre_tick)