Making BP Function Libraries Safer

Two freely available plugins to make Python-generated content safer to use in Unreal

The heart of the problem with Python-generated BP Function Libraries is that Python initialization happens too late in the Editor Startup Process.

The general order on startup looks something like this:

  1. Plugins are mounted

  2. The Default Map is opened in the Editor

  3. Any cached Editor Utility Widgets are reopened (EUWs that were open when the Editor was previously closed)

  4. Python Init startup is run

This page will show two available options to fix this issue, both are free plugins available online that allow us to run Python startup scripts before the Default Map has been loaded.


The Demo Code

For this demo I have a basic function library:

My Editor Utility Widget calls a BP Function from this module, in order to make it safe I need to run the following Python line as soon as possible:

from dev import function_library

If this code is not run soon enough, my Editor Utility Widget will be broken on Editor Startup when Unreal relaunches this tool:

Let's fix this!


the Python Blueprint Fixer plugin

This plugin is available on FAB, this plugin will run the Project's Python Startup Scripts before the Project's Default Map is loaded.

With the Plugin enabled:

We will need to open the Project Settings window and add our startup script:

The Blueprint Fixer Plugin will load the Python plugin and run its Startup Scripts immediately, anything declared here will run before the Default Map loads:

note: init_unreal.py scripts still run after the Default Map has been loaded

This is a Per-Project solution, each Project will need the appropriate entry in its Python Startup Scripts setting.


the Python Add Pre Init plugin

Disclaimer: This is a plugin I wrote

This plugin is available on FAB or my GitHub, this plugin adds support for a new Python startup script: pre_init_unreal.py

With the Plugin enabled:

We can add a pre_init_unreal.py file anywhere a init_unreal.py can be added:

and it will run before the Default Map loads:

note: init_unreal.py scripts still run after the Default Map has been loaded

Supported file locations for pre_init_unreal.py :

  • The Content/Python sub-folder in your Project's folder

  • The Content/Python sub-folder in the main Unreal Engine installation

  • The Content/Python sub-folder in each enabled Plugin's folder

  • The Documents/UnrealEngine/Python folder inside your user directory. For example, on Windows 10, this is equivalent to C:/Users/Username/Documents/UnrealEngine/Python

This is a flexible solution, it can be per-project, per-user, or per-plugin as desired.


Summary

Both of these options achieve the same goal: run desired Python code earlier in the startup process

The Python BP Fixer plugin is great for project-oriented usage, making use of what's already available

The Python Pre Init plugin is good for project-oriented and plugin-oriented usage, adding new functionality

Last updated