Automation library missing in Unreal Python, how do i include the library to my script

I have been trying to script a EXR screenshot tool for UE, using the take_high_res_screenshot function. But keep getting an error that says

LogPython: Error: AttributeError: type object ‘EditorLevelLibrary’ has no attribute 'get_all_viewports

Seems like the automation library missing, how do I fix this? can’t find any resources

take_high_res_screenshot does not belong to unreal.EditorLibrary (but to unreal.AutomationLibrary). Since the error is complaining about the EditorLibrary object I’m guessing you’re using get_all_viewports somewhere in your code and that object does not have that attribute.

You can try checking the Unreal Python docs for the Unreal version you’re using, maybe that get_all_viewports attribute has been deprecated or changed names.

These are the Unreal Python API docs for 5.4: https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/?application_version=5.4

Either way, I’ve just tried the following code inside Unreal and I could successfully take a screenshot with EXR format:

import unreal


unreal.AutomationLibrary.take_high_res_screenshot(1024, 1024, filename='your_path/image_name.exr')

Hope it helps! :slight_smile:

2 Likes

Thanks bunch, it works. I am really new to Python in UE. Do you have any clue how to integrate this script into the main UI? I am writing a UI for Unreal’s main interface. Do you have any thoughts?

Also I have been trying to calculate the viewport resolution rather than manually parsing the values, apparently get_all_viewports doesn’t exist in unreal.EditorLibrary are there any alternatives available? How do you calculating the current viewport resolution?

and tried take_automation_screenshot still says no attributes in automation library, any clue how do fix all of these

Glad it helped :slight_smile:

AFAIK you can either use UMG (Blueprint based) or slate (C++) to create custom UI in Unreal. You’ll find a lot of blueprint nodes operations if you use UMG, and if there’s something that’s only available in python you can always execute python code/scripts via blueprints nodes (e.g., https://www.youtube.com/watch?v=JP_EOAGS634). There’s plenty of tutorials online that teach how to implement UI in the engine.

I have no idea on how to get the viewport resolution, maybe there’s a blueprint node for it.

And regarding take_automation_screenshot error it’s hard to tell without seeing the code but I’d recommend checking the Python Unreal API docs as it looks there’s an attribute that does not exist.