how to play level with python?

image
Hi, there are commands for simulation but I did not find for PIE
unreal.LevelEditorSubsystem().editor_play_simulate()
or
unreal.EditorLevelLibrary().editor_play_simulate()
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.