How to use Unreal Python with VS Code

Setup

You don’t need python installed on your system, as Unreal Python is embedded into Unreal.

Unreal VersionPython Version
4.273.7.7
5.03.9.7

UE Python Plugin

In the UE Editor, we need to enable the python plugin.

  1. Edit > Plugins > Enable “Python Editor Script Plugin” (you’ll need to restart the UE editor)
  2. Window > Developer tools > Output Log
  3. Bottom Left of the Output Log, switch it from Cmd to Python

VS Code Autocomplete

First you will need enable to developer mode from the Editor:

  1. Edit > Project Settings > Plugins > Python > Enable “Developer Mode” and restart the editor.
  2. An unreal.py file will be created in PROJECT/Intermediate/PythonStub/unreal.py
  3. In VS Code: File > Preferences > Settings > Extensions > Python > Edit in settings.json
  4. Add the following .extraPaths to the VS Code settings.json
{
    ...

    "python.autoComplete.extraPaths": [
        ["C:\\path\\to\\PROJECT\\Intermediate\\PythonStub"]
    ]
    "python.analysis.extraPaths": [
        ["C:\\path\\to\\PROJECT\\Intermediate\\PythonStub"]
    ]
}

After this, VS code should have access to the python stub.

References

  1. Getting started with Python in UE4 by Sondre Utheim
    https://sondreutheim.com/post/getting_started_with_python_in_ue4
  2. Setting up Autocomplete for Editor Python Scripting
    https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/ScriptingAndAutomation/Python/Autocomplete/
  3. Unreal Python API