← All namespaces

python

Editor & system Core

Run Python in the editor interpreter. The general escape hatch for anything without a dedicated operation.

What it’s for

This namespace runs Python code inside Unreal’s built-in interpreter. It is a single operation that hands your script to the editor’s Python runtime and returns whatever it produced. You reach for it when you need the raw unreal.* API surface directly, without a typed operation in between.

It is the general-purpose escape hatch. Most things in this product have a dedicated, typed operation somewhere: spawning actors, editing Blueprints, inspecting widgets, dumping assets. Those give you structured input and output and clearer errors. Python is what you use when no typed operation covers the job — a niche editor function with no wrapper, or a tight loop over hundreds of objects that would otherwise be hundreds of separate calls.

Because of that, the rule is to use it sparingly. Before falling back to Python, your assistant should check whether a typed namespace already does the job — that path is safer and easier to read. Python is the last resort and the prototyping tool, not the default.

One thing to know: the interpreter runs synchronously on the editor’s game thread, so a long-running script stalls the editor. And the call reports transport success even when the Python itself failed, so your assistant reads the returned success, result, and log fields rather than assuming the script ran clean.

Examples

Run a Python script file

Point it at a .py file on disk and let the editor execute it in an isolated scope.

You: Run my batch-rename tool script against the project.

  call("python.execute", {code: "/Game/Scripts/batch_rename.py"})
    → {success: true, result: "", log: "renamed 47 assets"}

Done. Ran batch_rename.py; 47 assets renamed.

Evaluate a one-off expression

Use evaluate_statement mode to get a value back from a single Python expression.

You: How many assets are under /Game/MyGame?

  call("python.execute", {
        code: "len(unreal.EditorAssetLibrary.list_assets('/Game/MyGame/'))",
        mode: "evaluate_statement"})
    → {success: true, result: "312"}

Done. 312 assets under /Game/MyGame.

Keep state across calls

Run a statement in public scope so variables persist into a later call in the same shared globals.

You: Stash a base counter, then give me double it.

  call("python.execute", {code: "import unreal; MY_VAR = 42",
        mode: "execute_statement", scope: "public"})
    → {success: true}
  call("python.execute", {code: "MY_VAR * 2",
        mode: "evaluate_statement", scope: "public"})
    → {success: true, result: "84"}

Done. MY_VAR persisted; doubled value is 84.

← Back to all namespaces