Skip to content

Interfaces

How do I define and implement an Unreal interface?

Define an interface with @ue.uclass on a subclass of ue.Interface. Implement it with the interfaces option.

@ue.uclass
class Readable(ue.Interface):
    @ue.ufunction
    def read_value(self) -> int:
        return 0


@ue.uclass(interfaces=(Readable,))
class Counter(ue.Object):
    @ue.ufunction
    def read_value(self) -> int:
        return 42
  • Declare every implementation with @ue.ufunction, matching the interface's parameter and return types. Missing or incompatible implementations are rejected before an existing class is replaced.
  • interfaces= does not add Python base classes. To ask whether an object implements one:
ue.KismetSystemLibrary.does_implement_interface(obj, Readable)
  • Interface definitions declare functions, not state or components.