Skip to main content

05 - Low-Level Door

The richest example. A single door that combines a replicated flag, a dynamic multicast delegate, three components, a timer, clamping, and a Server function - everything networking-adjacent in one file.

Full source​

include "CoreMinimal.h"
include "GameFramework/Actor.h"
include "Components/BoxComponent.h"
include "Components/StaticMeshComponent.h"
include "Components/AudioComponent.h"
include "TimerManager.h"

uclass ADoor : AActor meta: api=MYGAME_API
{
declare DynamicMulticast FExampleDoorOpened (OneParam APawn*, Opener)

prop public bool bIsOpen protected EditAnywhere Replicated category="Door" default=false
field public FExampleDoorOpened OnDoorOpened
field public FTimerHandle AutoCloseTimer

component UBoxComponent "Trigger"
component UStaticMeshComponent "DoorMesh"
component UAudioComponent "DoorSound"

func public void SetOpen(bool Open) Server Reliable {
if (bIsOpen == Open) { return; }
bIsOpen = Open;
OnDoorOpened.Broadcast(GetInstigator());
}

func public void Server_OpenDoor() Server Reliable {
UE_LOG(LogTemp, Warning, TEXT("pos=%s rot=%s"), *GetActorLocation().ToString(), *GetActorRotation().ToString());
}

ctor {
Trigger = CreateDefaultSubobject<UBoxComponent>(TEXT("Trigger"));
DoorMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("DoorMesh"));
DoorSound = CreateDefaultSubobject<UAudioComponent>(TEXT("DoorSound"));

RootComponent = Trigger;
DoorMesh->SetupAttachment(Trigger);
}
}

Line by line​

  • declare DynamicMulticast FExampleDoorOpened (OneParam APawn*, Opener) - declares a DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam type that carries an APawn* (e.g. who opened the door).
  • prop public bool bIsOpen protected EditAnywhere Replicated ... - the door's state, marked Replicated. See Networking for what TPScript generates today (specifier pass-through) vs. the roadmap (full wiring).
  • field public FExampleDoorOpened OnDoorOpened - a member of the delegate type - this is what Blueprints bind to.
  • field public FTimerHandle AutoCloseTimer - a timer handle for auto-closing.
  • component UBoxComponent "Trigger" / UStaticMeshComponent "DoorMesh" / UAudioComponent "DoorSound" - three subobjects.
  • func public void SetOpen(bool Open) Server Reliable { ... } - a server-side reliable function. It guards (if (bIsOpen == Open) return;), flips the flag, then broadcasts OnDoorOpened with the instigator. Clients call SetOpen; authority applies it.
  • ctor { ... } - creates all three components and attaches DoorMesh to Trigger.

Concepts packed in​

  • Delegates: a multicast event with one APawn* parameter, broadcast via OnDoorOpened.Broadcast(GetInstigator());.
  • Replication markers: Replicated property + Server, Reliable function.
  • Clamping: default=false and the idempotent guard if (bIsOpen == Open) return;.
  • Components: three low-level components wired in the constructor.
  • Timer handle: declared for an auto-close timer you'd add with GetWorldTimerManager().SetTimer(...).

Notes on replication​

As documented in Networking, the Server/Reliable/Replicated specifiers parse and pass through, but GetLifetimeReplicatedProps and RPC _Implementation are not yet auto-generated - full wired replication is on the roadmap. Use this example as the authoring pattern.

Next: 06 - Enemy Spawner.