You can use the UE4Poco driver to connect to a running Unreal Engine game and interact with its UI tree via Python scripts.
Standard Connection
To connect to a running game process:
from poco.drivers.ue4 import UE4Poco
# Initialize the driver
poco = UE4Poco()
# Interact with a widget
# Example: clicking a button named 'StartButton'
poco("StartButton").click()
Editor Mode Connection
To connect while running in the Unreal Editor (PIE mode), pass ue4_editor=True. Note: The Unreal Editor language must be set to English for this to work.
from poco.drivers.ue4 import UE4Poco
# Initialize for editor mode
poco = UE4Poco(ue4_editor=True)
Custom Window Connection
If the automatic connection fails, you can manually specify the device handle in poco/drivers/ue4/device.py. For example, to connect to a specific Unreal window using a regular expression for its title:
# Example for older UE4 versions (pre-4.26) targeting 'Game Preview Standalone'
dev = connect_device("Windows:///?class_name=UnrealWindow&title_re=.*Game Preview Standalone.*")
# For UE4 versions 4.26 and above, the window name is typically 'Preview [NetMode: Standalone]'
from poco.drivers.ue4 import UE4Poco
poco = UE4Poco()
# example
poco("StartButton").click()