Python

About

← Back

Setup

Enable Python

Enable Python plugin in UE4 & restart UE4. Python settings will be available in Project Settings > Plugins > Python following restart.

Add new Python directory under project's Content directory.

Embedded Python 2.7 Location:

C:\Program Files\Epic Games\UE_4.25\Engine\Binaries\ThirdParty\Python\Win64

Python in UE4 Source

Stub File

In UE4, enable Project Settings > Plugins > Python > Developer Mode.

UE4 Python stub file will be located here:

<UE4_Project_File_Name>/Intermediate/PythonStub/unreal.py

Process for enabling and utilizing stub file in PyCharm: Link Stub File in PyCharm

Implementation

There are a few different ways of using Python within UE4:

UE4 Command Line

Access the bottom of the Output Log window in UE4 project.

Python Command

Select Python (REPL) from drop-down menu.

Enter Python commands directly into field.

SHIFT + ENTER for multiline input.

Run Function From Script

Select Python (REPL) from drop-down menu.

Looks to Content > Python directory for scripts.

Utilities

  • Utilities (personally-built) are being located within a folder titled 'utils'.

Workflow

  • Import module/s as applicable.
import utils.UtilityName
  • Access functions to run in command line.
utils.UtilityName.function(args)
  • Reload modifications to script and/or module/s as applicable.
reload(utils.UtilityName)

Run Full Script

Select Python from drop-down menu.

Include full path to the script or locate script in Content > Python directory and include relative path.

File Menu

Navigate to the UE4 project file's File > Execute Python Script... to run the specified script.

The File > Recent Python Scripts menu item holds a number of recent scripts that can be run without re-navigating to the script file location on disk.

Startup Scripts

init_unreal.py

Recognized by UE4 with the above noted file name.

Custom Startup Scripts

List under Project Settings > Plugins > Python > Startup Scripts and > Additional Paths based on where these files need to be accessed from on disk.

Blueprints

Using a Custom Event and Execute Console Command node, the Python script file can be accessed and run.

Note the Call in Editor option is enabled for the Custom Event to run the command from the blueprint's options under Details.

image

Remote Execution

Enable Feature

Project Settings > Plugins > Python > Enable Remote Execution

Module Location

C:\Program Files\Epic Games\<UE_version>\Engine\Plugins\Experimental\PythonScriptPlugin\Content\Python\remote_execution.py

Log Python Syntax

unreal.log_warning(<string>)

Function Help

help(<function_name>)

Hierarchy

Unreal Object

Resources

Resources

Support Tools

Support Tools