# The Execute Python Script Node

## The Execute Python Script Node

For general use, especially if releasing something to other users, it is recommended to use the Epic-provided Execute Python Script node. This is the most robust option, allowing us to run Python scripts and capture their output in the Blueprint Graph:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FFbg86Ix1YjANBANQNQig%2Fimage.png?alt=media&#x26;token=b2a305f8-b971-4240-90b4-525cefc62c12" alt="" width="329"><figcaption></figcaption></figure>

The advantage of this node is that we can declare its inputs and outputs in the Details panel, allowing us to pass wildcard data between Blueprints and Python:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FNGkRNumVwSuSQmZl8Bpe%2Fimage.png?alt=media&#x26;token=873d1e88-4900-49cf-afe3-ce261ad37af6" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FtRiT00Aw69KSKP3kFnGw%2Fimage.png?alt=media&#x26;token=daf8e83c-853d-4be1-b4aa-2de54c7f96cf" alt="" width="563"><figcaption></figcaption></figure>

***

## Inputs and Outputs

### The <mark style="color:yellow;">Success?</mark> bool return (UE5.5+)

The BP Graph does not track Python errors on its own, if any errors occur in our Python script the BP Graph will just continue on to the next node. The `Success?` default output allows us to abort an is a default return on the node, if any Python errors occur it will return `False`, allowing the opportunity to abort if needed:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FTF9Op7aGeADZn01S5Fzh%2Fimage.png?alt=media&#x26;token=782a3fe7-d54c-47fc-9798-f3199b1d64fa" alt="" width="363"><figcaption></figcaption></figure>

<mark style="color:yellow;">**Note:**</mark> This feature was fixed in **5.5**, it does not appear to work in 5.2-5.4 (tested December 2024)\
A workaround for affected Unreal versions is to provide our own `success` variable:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FSJF7hIm4fdsoQgdTuM3X%2Fimage.png?alt=media&#x26;token=4a16407a-2b14-4e41-84d2-8ee4a07e0e24" alt="" width="563"><figcaption></figcaption></figure>

### Custom Inputs and Outputs

Inputs and Outputs are added as wildcards by default on the node (colored grey). The BP Node relies on the Graph Pin connections to determine the variable type of each Input/Output.

For `Inputs` added in the Details Panel we will need to connect a Blueprint Graph Pin to provide their starting value + data type. Inputs are automatically initialized in the Python and are ready to use right away:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2Fy8v30Xjke58P1mP89PHh%2Fimage.png?alt=media&#x26;token=cbf714a2-fff7-49cb-ab00-bd7015752138" alt="" width="461"><figcaption></figcaption></figure>

For `Outputs` added in the Details Panel we also need to connect a Blueprint Graph Pin, this tells the Execute Python Script what data type to use for each output:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FFYVF0cVNHr57oOjPe9yo%2Fimage.png?alt=media&#x26;token=908a8b1a-33b4-4f85-8072-6436de3fad3a" alt="" width="404"><figcaption></figcaption></figure>

***

## Advantages

The main <mark style="color:green;">advantage</mark> of this method is its reliability, as long as the Python code inside is valid there shouldn't be a problem. This is the preferred method to run Python code from a Blueprint.

## Disadvantages

A cautionary <mark style="color:yellow;">disadvantage</mark> of this method is code management, especially for larger productions/pipelines. It can be tedious to keep track of and update every instance of these nodes across multiple blueprints.

One recommendation to help reduce the management burden is to keep the bulk of your code in external Python modules and just have the Python Script node import & call functions:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FItvWhgEQmW91VnqjHRec%2Fimage.png?alt=media&#x26;token=79de0ac2-2499-433d-8f49-542b0cb5bd7c" alt="" width="422"><figcaption></figcaption></figure>

A minor <mark style="color:yellow;">inconvenience</mark> is that the Inputs and Outputs are all wildcards relying on Pin connections to inform them of their data types. In some cases you may find yourself adding arbitrary nodes or extra variables just to declare the type:

<figure><img src="https://368271246-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FStUBkBT2qJGKNkIZ6yc7%2Fuploads%2FVcQLEMdcFqQpcdC821sy%2Fimage.png?alt=media&#x26;token=53626d30-5576-40b2-ae3a-904343a1f8a0" alt="" width="563"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bkortbus.gitbook.io/unreal-python-recipe-book/calling-python-from-blueprint/the-execute-python-script-node.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
