Structs and enums¶
How do I define a struct or enum Blueprints can use?
Enums¶
@ue.uenum turns an enum.IntEnum into an Unreal enum.
import enum
@ue.uenum
class ETeam(enum.IntEnum):
RED = 0
BLUE = 1
Values must be 0 to 254 (Blueprint enums are bytes). Unreal properties of the enum read as members of your class.
Structs¶
@ue.ustruct turns a subclass of ue.StructBase into an Unreal struct. Every annotated field (except ClassVar)
is an Unreal property and its value is the default.
@ue.ustruct
class Stats(ue.StructBase):
health: int = 100
team: ETeam = ETeam.RED
tags: list[str] = ue.uproperty(default_factory=list)
stats = Stats(health=50)
Construction works like a dataclass, and type checkers treat it as one. Methods stay Python-only. Do not define
__init__.
A struct may derive from one other @ue.ustruct class:
@ue.ustruct
class ShieldedStats(Stats):
shield: int = 25
Redeclaring an inherited field and multiple inheritance are rejected.
Evolving saved types¶
Adding struct fields or enum entries is supported, also for types already saved in assets. Removing or renaming a field, changing its type or flags, changing a struct's parent, or removing, renaming or renumbering an enum entry is rejected before the existing type is replaced. Create a new type and migrate the assets instead.