# 20tab/unrealenginepython architecture

> Architecture diagram of the GitHub repository 20tab/unrealenginepython, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/20tab/unrealenginepython
- Repository: https://github.com/20tab/unrealenginepython

## Overview

Based on our analysis of the file tree and the README, the project is a plugin for Unreal Engine that embeds a full Python Virtual Machine inside both the engine’s editor and runtime. Its purpose is to expose UE4’s extensive C++ API (including the reflection system, Slate UI, and other subsystems) to Python, thereby letting developers script gameplay, automate tasks, create editor tools, and extend the engine using Python code. The project is organized into several major submodules (for example, PythonAutomation, PythonConsole, PythonEditor, and UnrealEnginePython) along with documentation, examples, tests, tutorials, and platform-specific assets.

##### Main Components
- Plugin Initialization & Loader – This module is responsible for starting the Python VM within UE4. Include the build scripts and configuration files (e.g., the UnrealEnginePython.uplugin descriptor) that control whether the Python VM is loaded at runtime or just within the editor.
- Python VM Integration Layer – Represent the component that embeds Python (supporting both 2.7 and 3.x versions) and ties it into Unreal’s runtime. This layer also manages discovery and binding of the Python environment (as indicated by the Build.cs files and platform-specific directories like “android”).
- Unreal Engine API Bridge – Highlight the reflection-based mapping layer that automatically creates Python proxies for UObjects (the “ue_PyUObject” system), including the “proxy” classes like PyActor, PyPawn, PythonComponent, etc. This encapsulates the native method wrappers versus reflection calls.
- Submodules for Editor & Runtime Tools – Separate components for the Python Console, Python Editor, and additional automation modules. These parts allow executing Python commands from the editor, hooking into Unreal’s event system, and even run automated pipelines and tests (see the examples and tests directories).
- Platform-Specific Adaptation & Resources – Include platform-specific resources (such as the Android folder with various Python inclusions) and build tools (tools/, build scripts for Windows and macOS) that ensure the plugin can be built and deployed on multiple systems.

##### Component Relationships and Data Flow
- Flow from the Unreal Engine core to the plugin loader where the uplugin file triggers the build and initialization of the plugin.
- Demonstrate how the Python VM integration layer passes control to the API Bridge, which exposes engine objects as Python proxies.
- How external scripts (from the Scripts directory and tutorials) interact with the proxy system, thereby automating or extending engine behavior.
- Directional interactions such as the binding of events (e.g., actor events, tick updates, delegate invocations) from Unreal’s C++ systems to Python callback modules.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly segment the plugin into layers (initialization, integration, API bridging, UI/editor components, etc.) so that each part has a well-defined responsibility.
- Proxy Pattern: Highlight how the system uses proxy classes (Python classes that hold a reference to a ue_PyUObject) so that Python code can interface naturally with Unreal’s native objects.
- Reflection vs. Native Access: Distinguish components that rely on Unreal’s reflection system (e.g., dynamically mapping functions and properties) from those that use direct/native calls for performance.
- Modularity: Ensure that each module (PythonAutomation, PythonConsole, PythonEditor, UnrealEnginePython) is represented as a distinct block to reinforce clarity and maintainability.

##### Relevant Technologies, Frameworks, and Libraries
- Unreal Engine (UE4) as the overall platform.
- The embedded Python VM, supporting multiple versions.
- The build and deployment systems (highlight build scripts, platform resources, and the uplugin descriptor).
- Slate UI for the integrated Python Editor and console.
- External asset and third-party library support (such as Fbx SDK integration, and potential open-source tooling for third-party editors).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Components
    UE4["Unreal Engine Core"]:::engine
    PluginLoader["Plugin Initialization & Loader"]:::loader
    PythonVM["Python VM Integration Layer"]:::integration
    APIBridge["Unreal Engine API Bridge (Python Proxy System)"]:::bridge

    %% Submodules for Editor & Runtime Tools
    subgraph "Editor & Runtime Tools"
        PythonAutomation["PythonAutomation Submodule"]:::submodule
        PythonConsole["PythonConsole Submodule"]:::submodule
        PythonEditor["PythonEditor Submodule"]:::submodule
    end

    %% Platform-Specific Resources
    PlatformResources_Android["Android Resources"]:::platform
    BuildScripts["Build Scripts & Tools"]:::platform

    %% External Integrations
    ExternalIntegrations["External Integrations"]:::external

    %% Connections
    UE4 -->|"triggers"| PluginLoader
    PluginLoader -->|"loads"| PythonVM
    PythonVM -->|"binds_to"| APIBridge
    APIBridge -->|"exposes_to"| PythonConsole
    APIBridge -->|"exposes_to"| PythonEditor
    APIBridge -->|"supports"| PythonAutomation
    PythonConsole -->|"commands_to"| APIBridge
    PythonEditor -->|"commands_to"| APIBridge
    PythonAutomation -->|"automates_via"| APIBridge
    PlatformResources_Android -->|"supports"| PythonVM
    BuildScripts -->|"supports"| PythonVM
    ExternalIntegrations -->|"enhances"| APIBridge
    UE4 -->|"event_binding"| PythonConsole

    %% Click Events
    click PluginLoader "https://github.com/20tab/unrealenginepython/blob/master/UnrealEnginePython.uplugin"
    click PythonVM "https://github.com/20tab/unrealenginepython/tree/master/Source/UnrealEnginePython"
    click APIBridge "https://github.com/20tab/unrealenginepython/tree/master/Source/UnrealEnginePython/Private/UObject"
    click PythonAutomation "https://github.com/20tab/unrealenginepython/tree/master/Source/PythonAutomation"
    click PythonConsole "https://github.com/20tab/unrealenginepython/tree/master/Source/PythonConsole"
    click PythonEditor "https://github.com/20tab/unrealenginepython/tree/master/Source/PythonEditor"
    click PlatformResources_Android "https://github.com/20tab/unrealenginepython/tree/master/android"
    click BuildScripts "https://github.com/20tab/unrealenginepython/tree/master/tools"
    click ExternalIntegrations "https://github.com/20tab/unrealenginepython/tree/master/Source/UnrealEnginePython/Private/Fbx"

    %% Styles
    classDef engine fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef loader fill:#b4e197,stroke:#333,stroke-width:2px;
    classDef integration fill:#a9d0f5,stroke:#333,stroke-width:2px;
    classDef bridge fill:#f5a9a9,stroke:#333,stroke-width:2px;
    classDef submodule fill:#e3cef6,stroke:#333,stroke-width:2px;
    classDef platform fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef external fill:#fdebd0,stroke:#333,stroke-width:2px;
```
