Skip to content

Where to run Python

There are four places to run Python in Starcel.

1. Code cells in the world

Press = to spawn a code cell in front of you, type Python, and press Ctrl+Enter to run it. Press Esc to stop typing.

from entity import Entity
Entity(model='sphere', y=2)

Inside a cell, actor is the cell itself. Some functions use it to draw next to the cell, for example graph(..., at=actor) in geometric algebra. Running the cell again replaces what it drew.

Cells in a table work the same way: click a cell, type, and press Ctrl+Enter. A cell that starts with = is a formula, like =B2 * C2.

2. The Unreal console

Press ` to open the console. Two commands run Python:

py.cmd "from ue_spawn import spawn; spawn('cube')"
py.exec my_script.py

py.cmd runs a line of Python. Put it in double quotes: each word outside quotes becomes its own line. py.exec runs a file from Content/Scripts.

3. main.py

Content/Scripts/main.py runs when the map starts. Put code there that you want every time, such as your background or the objects you always use. Code that spawns things belongs in begin_play:

class Main:
    def begin_play(self):
        from entity import Entity, color
        Entity(model='cube', color=color.azure, y=1)

    def tick(self, delta_time):
        pass

4. Your own PyActors

A PyActor is an actor that runs a Python class. It has begin_play and tick and can react to clicks and overlaps. See PyActors.

from ue_spawn import spawn_pyactor
spawn_pyactor('my_module', 'MyClass')

Where your files are

Folder What
Content/Scripts All Python. It is on sys.path, so import entity works.
Content/Models Model files that Entity(model='duck.glb') finds by name.
Saved/Tables Tables you save, such as the camera settings.
Saved/Manim Cached manim recordings.