Skip to content

Run code at game startup

How do I start my game from Python?

Use this when you want a function to run once at game launch. For logic that belongs to an actor, use begin_play so you can try it in Play In Editor.

# Python/mygame/boot.py
import ue


def main(_args: list[str]) -> None:
    world = ue.get_world()
    ue.log(f"Started in {world.get_name() if world else 'no world'}")
  1. In Edit → Project Settings → Plugins → UnrealPy, set Startup Module to mygame.boot:main.

    The singular Startup Module field set to mygame.boot:main

  2. Save the project and restart Unreal Editor if prompted.

  3. Open the ⋮ menu beside Play and choose Standalone Game. Look for the startup message in the log.

    The menu next to Play with Standalone Game listed under Modes

The function runs once when the game starts, including in a packaged game. Use Standalone Game to test it in the editor.

Other startup hooks

  • Startup Modules imports modules once the engine and interpreter are ready.
  • Class Modules and Class Packages register modules that define Unreal types. See Project settings.