# Organizing Startup Scripts

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:

1. There may be multiple init\_unreal.py files in the Python Path, making it ambiguous if there are any errors
2. 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:

```python
import sys
from pathlib import Path

print("init_unreal modules available:")
for folder_path in sys.path:
    for init_file in Path(folder_path).glob("init_unreal.py"):
        print(f"\t{init_file.resolve()}")

print("Location of imported init_unreal:")
import init_unreal
print(f"\t{init_unreal.__file__}")
```

<figure><img src="/files/8WX8X6NG7eHMBmapdQM4" alt=""><figcaption></figcaption></figure>

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:

1. Create a separate module for my startup script
2. 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:

<figure><img src="/files/f17BNjhRySrWzYhN8c5a" alt=""><figcaption></figcaption></figure>

With this setup my `init_unreal.py` file usually looks something like this:

```python
from recipe_book import startup
startup.run()
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bkortbus.gitbook.io/unreal-python-recipe-book/startup-and-shutdown-scripts/organizing-startup-scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
