# Python API/highrescreenshot

**URL:** <https://forums.unrealengine.com/t/python-api-highrescreenshot/132783>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [October 30, 2019, 11:51am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783 "2019-10-30T11:51:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![frost-xyz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@frost-xyz](https://forums.unrealengine.com/u/frost-xyz)\
**Post date:** [October 30, 2019, 11:51am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/1 "2019-10-30T11:51:10Z")

</div>

Can’t see any mention of the High Res Screenshot tool in the [Python documentation](https://docs.unrealengine.com/en-US/PythonAPI/index.html).  
Is this planned for the future?

---

<div class="post-metadata">

**Author:** ![frost-xyz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@frost-xyz](https://forums.unrealengine.com/u/frost-xyz)\
**Post date:** [October 30, 2019, 11:53am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/2 "2019-10-30T11:53:36Z")

</div>

Found it.  
[https://docs.unrealengine.com/en-US/PythonAPI/class/AutomationLibrary.html?highlight=screenshot#unreal.AutomationLibrary.take\_high\_res\_screenshot](https://docs.unrealengine.com/en-US/PythonAPI/class/AutomationLibrary.html?highlight=screenshot#unreal.AutomationLibrary.take_high_res_screenshot)

---

<div class="post-metadata">

**Author:** ![mamoniem](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mamoniem/32/1194698_2.png) [@mamoniem](https://forums.unrealengine.com/u/mamoniem)\
**Post date:** [June 17, 2020, 2:15am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/4 "2020-06-17T02:15:16Z")

</div>

> [@V2i](#):
>
> did you by any change manage to take multiple screenshots? I cant get the is\_task\_done() working.

you might need to consider the scoped slow tasks.

---

<div class="post-metadata">

**Author:** ![Andreas\_Ranman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andreas\_Ranman](https://forums.unrealengine.com/u/Andreas_Ranman)\
**Post date:** [June 17, 2020, 8:09am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/6 "2020-06-17T08:09:11Z")

</div>

Think a limitation of screenshot is that you can only do one per tick (frame), so you will have to make a way to somehow wait for tick to happen.

We solved this by having the python bridge run a method in tick that we implement in the python class to return next for generator functions. Not fully clear on the implementation but allows us to run

```auto

for _ in TakeMultipleScreenshots():
  yield MyEnum.WaitForNextFrame

```

Think I’ve seen that you can attach functions as callbacks to slate which to me seems like a much better solution but our method worked so haven’t touched it since.

---

<div class="post-metadata">

**Author:** ![Andreas\_Ranman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Andreas\_Ranman](https://forums.unrealengine.com/u/Andreas_Ranman)\
**Post date:** [June 23, 2020, 9:35am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/8 "2020-06-23T09:35:13Z")

</div>

```auto

import unreal
import time

class OnTick(object):
  """ Register a function and run it on tick, """
  def __init__ (self):
    # make a generator function so we can call next on it,
    self.actors = (actor for actor in unreal.EditorLevelLibrary.get_selected_level_actors())

    # register a callback on tick
    self.on_tick = unreal.register_slate_post_tick_callback(self. __tick__ )

  def __tick__ (self, deltatime):
    """ Function we will call every tick, """
    try:
      print(deltatime) # Print the deltatime just for sanity check so we
      # know a tick was made,

      # Get the next actor from our generator function,
      actor = next(self.actors)
      actor_location = actor.get_actor_location()

      # Solve the camera position, and rotation
      position = actor_location + unreal.Vector(200.0, 200.0, 200.0)

      # roll, pitch, yaw
      rotation = unreal.Rotator(0.0, -45.0, -130.0)

      unreal.EditorLevelLibrary.set_level_viewport_camera_info(
        position,
        rotation
      )

      # Take the screenshot,
      unreal.AutomationLibrary.take_high_res_screenshot(
        1920,
        1080,
        actor.get_name() + ".png"
      )

    except Exception as error:
      print(error)
      unreal.unregister_slate_post_tick_callback(self.on_tick)

if __name__ == ' __main__':
  instance = OnTick()

```

Seeing people using it to hook up Qt event to it [https://github.com/techartorg/TAO-Wi…ndow-BaseClass](https://github.com/techartorg/TAO-Wiki/wiki/Tickable-PySide2-Window-BaseClass) I based this example from that.

---

<div class="post-metadata">

**Author:** ![NoobNotPro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NoobNotPro](https://forums.unrealengine.com/u/NoobNotPro)\
**Post date:** [September 16, 2020, 11:33pm UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/9 "2020-09-16T23:33:39Z")

</div>

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

```auto

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)

```

---

<div class="post-metadata">

**Author:** ![PengSengAng](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PengSengAng](https://forums.unrealengine.com/u/PengSengAng)\
**Post date:** [January 25, 2022, 2:07am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/10 "2022-01-25T02:07:34Z")

</div>

this still skips a few screenshots for me. anyone has a better fix for this?

---

<div class="post-metadata">

**Author:** ![PecaPospec](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pecapospec/32/491293_2.png) [@PecaPospec](https://forums.unrealengine.com/u/PecaPospec)\
**Post date:** [May 20, 2022, 8:31am UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/11 "2022-05-20T08:31:31Z")

</div>

Is it also possible to automate screenshots of buffer visualisation targets such as world depth mask, opacity mask, etc? Above code produces only .png for me and I am unable to find any reference for additional buffers.

Thank you very much in advance 🙂

---

<div class="post-metadata">

**Author:** ![NoboluOotsukaUE](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/noboluootsukaue/32/469262_2.png) [@NoboluOotsukaUE](https://forums.unrealengine.com/u/NoboluOotsukaUE)\
**Post date:** [March 2, 2023, 5:19pm UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/12 "2023-03-02T17:19:15Z")

</div>

This IS Good Fix Code

```auto
import unreal
import time

class OnTick(object):
  """ Register a function and run it on tick, """
  def __init__ (self):
    # make a generator function so we can call next on it,
    
    EditorLevelLibrary = unreal.EditorLevelLibrary()
    all_level_actors=EditorLevelLibrary.get_all_level_actors()
    CameraActors=[]
    for actor in all_level_actors:
        #CameraBool=actor.find_camera_component_when_view_target
        CameraComponent=actor.get_component_by_class(unreal.CameraComponent)
        #print("CameraComponent="+str(CameraComponent))
        #className=CameraComponent.get_class() 
        #print("CameraComponent.get_class() ="+str(className))
        if(str(CameraComponent)=="None"):
            pass
        else:
            #if(str(CameraComponent) in "CineCameraComponent"):
            # pass
            #else: 
            CameraActors.append(actor)
    
    self.CameraActors=CameraActors
    #self.actors = (actor for actor in unreal.EditorLevelLibrary.get_selected_level_actors())
    self.actors = iter(CameraActors)
    
    self.tickcount=0
    
    # register a callback on tick
    self.on_tick = unreal.register_slate_post_tick_callback(self. __tick__ )
    
    
    
  def __tick__ (self, deltatime):
    """ Function we will call every tick, """
    try:
      print(deltatime) # Print the deltatime just for sanity check so we
      # know a tick was made,
        
      # Get the next actor from our generator function,
      actor = next(self.actors)
      """
      actor_location = actor.get_actor_location()
      actor_rotation = actor.get_actor_rotation() 
      # Solve the camera position, and rotation
      position = actor_location + unreal.Vector(0.0, 0.0, 0.0)

      # roll(z), pitch(tate), yaw(yoko)
      rotation = unreal.Rotator(actor_rotation.roll+0.0, actor_rotation.pitch+5.0,actor_rotation.yaw+0.0)
      
      unreal.EditorLevelLibrary.set_level_viewport_camera_info(
        position,
        rotation
      )
      """
      try:
          CameraComponent=actor.get_component_by_class(unreal.CameraComponent)
          print("actor= "+str(actor))
          print("CameraComponent= "+str(CameraComponent))
          unreal.AutomationLibrary.take_high_res_screenshot(
            1920,
            1080,
            actor.get_name() + ".hdr",
            camera=actor,
            capture_hdr=True,
            comparison_tolerance=unreal.ComparisonTolerance.HIGH,
            delay=0.25
          )
      except Exception as error:
          pass
      """
      unreal.EditorLevelLibrary.pilot_level_actor(actor)
      unreal.EditorLevelLibrary.editor_set_game_view(True)
      # Take the screenshot,
      unreal.AutomationLibrary.take_high_res_screenshot(
        1920,
        1080,
        actor.get_name() + ".hdr",
        camera=actor,
        capture_hdr=True,
        comparison_tolerance=unreal.ComparisonTolerance.HIGH,
        delay=0.25
      )
      
      unreal.EditorLevelLibrary.eject_pilot_level_actor()
      """
      # Count
      self.tickcount=self.tickcount+1
      
      CameraActors=self.CameraActors
      CameraActorsLen=len(CameraActors)
      endActor=CameraActors[CameraActorsLen-1]
      print("self.tickcount="+str(self.tickcount)+" :CameraActorsLen="+str(CameraActorsLen))
      if(str(self.tickcount)==str(CameraActorsLen)):
          print("finish")
          unreal.unregister_slate_post_tick_callback(self.on_tick)
      
    except Exception as error:
      #pass
      print(error)
      try:
          unreal.unregister_slate_post_tick_callback(self.on_tick)
      except Exception as error:
          pass
#if __name__ == ' __main__':
instance = OnTick()

```

> **[\[Unreal Engine\]複数のカメラのスクリーンショットを自動的に撮るPython – FURCRAEA.TOKYO](https://furcraea.verse.jp/wp/2023/03/02/unreal-engine-automationlibrary-take_high_res_screenshot/)**

---

<div class="post-metadata">

**Author:** ![Reojo22](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Reojo22](https://forums.unrealengine.com/u/Reojo22)\
**Post date:** [January 12, 2024, 4:27pm UTC](https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/13 "2024-01-12T16:27:08Z")

</div>

I had the same problem, and had to check whether the capture was done or not. See here:

> [@Unable to execute MoviePipelineQueue from Python](https://forums.unrealengine.com/t/unable-to-execute-moviepipelinequeue-from-python/467250/19):
>
> I’ve done something similar with take\_high\_res\_screenshot, in case that’s helpful. This code will take a screenshot from the point of view of “CameraOne”. It does fine on all the frames except the first one, so I added a bogus frame at the start of the level sequence (frame -1). Note that the settings for high res screenshots are very persistent. If the quality is too low, you might look at the options (hidden under the three-bar menu in the upper left of the viewport). I’m sure this is ineleg…
