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 fromAActor.api=sets the export macroEXAMPLES_API(matches the demo moduleExamples).prop public FName Message EditAnywhere BlueprintReadWrite category="Example" default="Hello from TPScript!"- a Blueprint-readable/writableFNameshown 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 { ... }- overridesBeginPlay, callsSuper::, and logs if enabled.method public virtual void Tick(float DeltaTime) override { ... }- the per-frame tick (left empty here).
Generated output
Public/.../AExampleHello.h- theUCLASSwith twoUPROPERTYs and the twovirtualoverrides.Private/.../AExampleHello.cpp-BeginPlay/Tickbodies callingSuper::.
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
ifshort-circuits). - Add a Tick body that moves the actor, e.g.
AddActorLocalRotation(FRotator(0, 30.0f * DeltaTime, 0));.
Next: 02 - Properties & Types.