Skip to main content

USTRUCT, UENUM & interfaces

Beyond actors you'll often need data structs, enums, and interfaces. TPScript supports all three natively.

USTRUCT - data structs​

Name must start with F. Add (BlueprintType) to expose it to Blueprints; make members public for BP access.

ustruct FWeaponStats (BlueprintType)
{
prop public int32 Damage default=10
prop public float FireRate default=1.0f
prop public FName Tag
}

Then use it as a property on a class:

uclass AMyWeapon : AActor meta: api=MYGAME_API
{
prop public FWeaponStats Stats EditAnywhere BlueprintReadWrite
}

USTRUCT specifiers​

BlueprintType, NotBlueprintType, BlueprintReadOnly, Blueprintable, BlueprintInternalUseOnly, Atomic, NoExport, Immutable, plus DisplayName= and meta(...).

UENUM - enums​

Header-only. Underlying type via : type (default uint8).

uenum EDamageType : uint8 (BlueprintType)
{
entry Physical
entry Fire
entry Electric = 2
entry Ice display_name="Frozen"
}

UENUM specifiers​

BlueprintType, Blueprintable, NotBlueprintType, NotBlueprintable, InternalUse, plus DisplayName= and meta(...).

Entry keywords​

display_name / display = "...", meta(...), and an explicit value: = <value>.

Interfaces - UINTERFACE + I-interface​

Interface methods are declared with method ... pure (→ pure virtual, = 0). Name auto-prefixes with I if not present; the abstract class is generated as U<Name>.

interface IExampleDamagable (api=EXAMPLES_API, minimal)
{
method public virtual void TakeDamage(float Amount) pure
}

Interface specifiers​

SpecifierEffect
minimalMinimalAPI
not_blueprintableNotBlueprintable
api=...which API macro to use

Implementing an interface​

uclass AExampleRobot : AActor implements IExampleDamagable meta: api=EXAMPLES_API
{
method public virtual void TakeDamage(float Amount) override {
UE_LOG(LogTemp, Warning, TEXT("robot took %f damage"), Amount);
}
}
  • Multiple interfaces: implements IFoo, IBar.
  • Implement the interface's pure methods with real bodies using override.

Putting it together (data-driven)​

07-data-driven-weapon.tps shows the classic combo: a USTRUCT + an actor that exposes it and derives stats:

ustruct FWeaponStats (BlueprintType)
{
prop public int32 Damage default=10
prop public float FireRate default=1.0f
}

Next: Statement sugar & expressions.