Skip to content

Your first Python actor

Make a Beacon actor that prints a message when you press Play. Start in Unreal Editor with UnrealPy enabled.

Create Beacon in the Content Browser

  1. Open the Content Drawer and select your project's Content folder. Click Add, search for New Python Class, and choose New Python Class....

    The Content Browser’s Add menu filtered to New Python Class

  2. Choose Actor as the parent class so you can place Beacon in a level.

    The parent class picker with Actor at the top of the common class list

  3. Enter Beacon in Name. Leave Folder (Python Classes) set to scripts. The dialog shows the destination, Python/scripts/beacon.py.

    The New Python Class dialog with Actor as the parent, Beacon as the name, and Python/scripts/beacon.py as the destination

  4. Click Create Class. UnrealPy generates the file, registers Beacon, and opens the script in your text editor. In a fresh project, it also creates the Python/scripts/ folder. Beacon is available immediately under Python Classes.

To reopen the script, double-click Beacon under Python Classes → scripts in the Content Browser. If the folder is hidden, enable Python Classes in Content Browser Settings. If the file doesn't open, check your text editor setting.

Give Beacon a message

Replace the starter code in the generated file with this version and save. The @ue.uclass decorator exposes Beacon to Unreal and ue.uproperty makes Message editable in Details.

import ue


@ue.uclass
class Beacon(ue.Actor):
    message: str = ue.uproperty(
        "Beacon is online",
        category="Beacon",
    )

    def begin_play(self) -> None:
        ue.log(self.message)

    @ue.ufunction(pure=True, category="Beacon")
    def get_message(self) -> str:
        return self.message

Place Beacon and press Play

  1. In the Content Browser, select Beacon under Python Classes → scripts. Right-click where you want to place it in the level viewport. Open Place Actor and choose Beacon under Selection.

    The viewport’s Place Actor submenu with Beacon under Selection

  2. Select the placed Beacon in the Outliner. In Details, find Beacon → Message and change it to Beacon is ready.

    The selected Beacon actor and its Message property set to Beacon is ready in Details

  3. Open Window → Output Log and press Play. Search the log for Beacon is ready. Unreal calls begin_play and Python prints the value you set in Details.

    The filtered Output Log showing Beacon is ready in the LogUnrealPy category

  4. Stop play and save the level.

Use Beacon as a Blueprint parent

  1. In Python Classes, right-click Beacon and choose Create Blueprint class based on Beacon.
  2. Name it BP_Beacon, select your Content folder, and click Create Beacon Class. Unreal opens the new Blueprint.
  3. Open EventGraph, right-click an empty area, and search for Get Message. Choose Get Message under Beacon. The node returns this actor’s Message because the Python method uses @ue.ufunction.

    The Blueprint action menu with the inherited Get Message function under Beacon

  4. Click Compile, then save the Blueprint.

Next, build an interactable door to wire up Blueprint input and a Python event dispatcher. You can also try hot reload or add Python to a Blueprint you already use.