how to play level with python?

Hi, there are commands for simulation but I did not find for PIE
but no command unreal.LevelEditorSubsystem().editor_play()

Hey there @jenios3! Welcome to the community! Judging by the documentation on the API and that the python commands also come from the Blutility nodes/code, it doesn’t seem like there’s a python based way to launch PIE. I can’t find anything exposed for Blutilities either so it’s possible it may need a source edit. Are you working from the launcher version?

Yes, in 5.0.3
But I don’t know C++ well.
Theoretically, I understand that you need to create your own function, which should work as a play button and which can be called in python.
What files need to be changed and with what code?

  1. 4 Ways To Level Up Your Python Code. Avoid unnecessary loops, access dictionary items more effectively, and more
  2. Replace range(len()) With enumerate()
  3. Stop Using Square Brackets To Get Dictionary Items — Use .get()
  4. Simplify Iterating Over Multiple Lists With Zip()
  5. Use f-strings To Easily Print to the Console.

I need to understand how to run PIE from python

I’ll have to dig into the source a bit to verify if it would be a simple function call. My bets are it’s going to be a little more involved since there’s no base command for it as of yet.

I was able to find something similar but I couldn’t run this code

FLevelEditorModule& LevelEditorModule = FModuleManager::Get().GetModuleChecked<FLevelEditorModule>(TEXT("LevelEditor"));
TSharedPtr<class ILevelViewport> ActiveLevelViewport = LevelEditorModule.GetFirstActiveViewport();

GUnrealEd->RequestPlaySession(false, ActiveLevelViewport, bSimulateInEditor, NULL, NULL, -1, false);

Apparently something has changed in 8 years or I’m doing something wrong

Hrm looks like it hasn’t changed much. Looking at the docs the params seem to have changed a bit. Are there any errors on the output? Might need to write it a bit more custom looking at these docs.

I’m looking to do something similar and wondered if you found a solution. Ideally I want to do this in Python.

I still haven’t found a way to run PIE

@jenios3 @KidAWS I am also trying to play the current level through the Unreal Python API but can’t seem to find a solution. Have any of you found a way to do it yet?

following works for my case. I execute python script which contains following:

import pyautogui
import time

You need to install pyautogui library.

However, this only works if editor is open and it does simple keypress, but may not be useful for other scenarios.