A plugin for automatically running python entrypoints on init_unreal

I authored a really quick plugin I wanted to share. Because I needed it.

leith-bartrich/PythonUnrealEntrypoint (github.com)

It’s simple but I think it’s also very useful. And I’d suggest it’s a simple feature Unreal Engine should include by default. My implementation is stupidly simple and meant to get out of the way if Unreal adopts the idea of running an entrypoint at init later on.

tldr: It runs a setuptools entrypoint on Unreal’s init. Any python package that publishes a “init_unreal” entrypoint will have it run during unreal’s init. This is important because it allows a python package you’d install via pip or setuptools, to run code at init_unreal time, and register the usual UObjects and such you’d want it to.

explanation:

In my experience, there are two major ways to write python code libraries for unreal.

  1. Put it in a Content/Python directory.

  2. Write a proper python package with a setup.py or the like, and install via pip (./Engine/Binaries/ThirdParty/Python3/Win64/python.exe -m pip install [blah])

The problem with #1 is that you don’t get to use setuptools and all the niceties like auto-installed pre-reqs. No ‘pip install’ and no ‘pip install -e’. Further, since the broader python ecosystem often assumes setuptools, it makes it frustrating to be operating outside that system.

The problem with #2 is that you don’t get an easy to use init_unreal mechanism with which to register UObjects and the like. init_unreal doesnt extend to setuptools based packages.

This plugin solves the problem by (internally) using a Contet/Python/init_unreal.py to call a generic ‘init_unreal’ entrypoint. When the plugin is installed and enabled, any setuptools based python package can participate in the init_unreal system.

Problem sovled. Unreal now better plays with the established python packaging and package development world.

usage:

in your setup.py file, add an entrypoint named: ‘init_unreal’

python documentation of entrypoints: Entry Points - setuptools 65.6.3.post20221124 documentation (pypa.io)

example setup.py file from an internal project:

from distutils.core import setup

setup(
    name='fpipe_unreal',
    version='0.1.0',
    packages=['fpipe_unreal'],
    url='',
    license='',
    author='FIE LLC',
    author_email='',
    description='Tools for working in Unreal within the fpipe environment',
    entry_points={
        'init_unreal' : [
            'fpipe_unreal = fpipe_unreal.init_unreal:init_unreal',
        ]
    },
)

for reference, the example entrypoint located at fpipe_unreal/init_unreal.py:

import unreal


def init_unreal():
    unreal.log("TADA!")

When installed via pip to the unreal engine, this code runs and you get a “TADA!” in the unreal console. When installed with pip install -e, the package additionally remains editable and easy to develop with.