# how to play level with python?

**URL:** <https://forums.unrealengine.com/t/how-to-play-level-with-python/679266>\
**Category:** Editor Scripting\
**Tags:** Python, unreal-engine, question\
**Created:** [October 29, 2022, 2:09am UTC](https://forums.unrealengine.com/t/how-to-play-level-with-python/679266 "2022-10-29T02:09:05Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jenios3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jenios3](https://forums.unrealengine.com/u/jenios3)\
**Post date:** [November 3, 2022, 5:56am UTC](https://forums.unrealengine.com/t/how-to-play-level-with-python/679266/7 "2022-11-03T05:56:57Z")

</div>

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

> [@How to launching a PIE session from code](https://forums.unrealengine.com/t/how-to-launching-a-pie-session-from-code/298563):
>
> I am writing some automated tests and I need the game to be running to test what I want to test. I guess the best way to do this is to launch a PIE at the start of the test (and preferably kill it at the end). How is this to be done? I am trying to use: GEngine-\>CreatePIEWorldByDuplication(Context, GEngine-\>GetWorldContexts()[0].World(), MapName); But can’t seem to get it to work (passing in an uninitialised context and either an empty string for MapName or a string with a “/Game/Maps/MassOce…

```auto
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

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-play-level-with-python/679266)._
