Organizing Startup Scripts
going beyond the init_unreal.py file
This section is especially subjective, while it's perfectly fine to put a lot of stuff in the init_unreal.py I don't like to do that from an organizational standpoint. I typically make a separate startup.py
file that the init_unreal.py
file impots and executes.
The two main reasons I do this is that:
There may be multiple init_unreal.py files in the Python Path, making it ambiguous if there are any errors
This provides a dedicated module I can inspect / reference elsewhere as needed
Examining init_unreal
Because Unreal executes every init_unreal.py file it fins in sys.path, it means there could be any number of competing python modules of the same name
To demonstrate this, here is a code snippet that lists the available init_unreal files and then shows which one is currently importable:
In this situation there are several init_unreal files, while Unreal does execute them all it's tricky to debug or inspect a specific startup script after Unreal opens.
Namespacing Our Code / Startup
To make startup (and the rest of my code) clearer to reference and debug I generally do two things:
Create a separate module for my startup script
Create a folder for everything but the init_unreal module
This guarantees my startup module can be accessed after Unreal opens and makes it clearer that all of my modules are coming from the same folder:
With this setup my init_unreal.py
file usually looks something like this:
Last updated