Skip to main content

01 - Hello Actor

The simplest possible TPScript file: a bare-bones actor with an editable property and a couple of overrides. This is the "Hello World" of the language.

Full source​

include "CoreMinimal.h"
include "GameFramework/Actor.h"

uclass AExampleHello : AActor meta: api=EXAMPLES_API
{
prop public FName Message EditAnywhere BlueprintReadWrite category="Example" default="Hello from TPScript!"
prop public bool bShowOnBegin EditAnywhere BlueprintReadWrite category="Example" default=true

method public virtual void BeginPlay() override {
Super::BeginPlay();
if (bShowOnBegin)
{
UE_LOG(LogTemp, Warning, TEXT("%s"), *Message.ToString());
}
}

method public virtual void Tick(float DeltaTime) override {
Super::Tick(DeltaTime);
}
}

Line by line​

  • include "CoreMinimal.h" / include "GameFramework/Actor.h" - pull in the headers the actor needs.
  • uclass AExampleHello : AActor meta: api=EXAMPLES_API - declares an actor class deriving from AActor. api= sets the export macro EXAMPLES_API (matches the demo module Examples).
  • prop public FName Message EditAnywhere BlueprintReadWrite category="Example" default="Hello from TPScript!" - a Blueprint-readable/writable FName shown in the Details panel, defaulting to the string.
  • prop public bool bShowOnBegin ... default=true - a toggle that controls whether we log.
  • method public virtual void BeginPlay() override { ... } - overrides BeginPlay, calls Super::, and logs if enabled.
  • method public virtual void Tick(float DeltaTime) override { ... } - the per-frame tick (left empty here).

Generated output​

  • Public/.../AExampleHello.h - the UCLASS with two UPROPERTYs and the two virtual overrides.
  • Private/.../AExampleHello.cpp - BeginPlay / Tick bodies calling Super::.

What to try​

  • Inside the editor, change Message in the Details panel and re-simulate to see the log update.
  • Uncheck bShowOnBegin to make the log disappear (the if short-circuits).
  • Add a Tick body that moves the actor, e.g. AddActorLocalRotation(FRotator(0, 30.0f * DeltaTime, 0));.

Next: 02 - Properties & Types.