๐งฉ Blueprint Basics
| Event BeginPlay | Runs once when actor spawns |
| Event Tick | Runs every frame (Delta Seconds) |
| Branch | If/else for boolean conditions |
| Sequence | Run multiple outputs in order |
| Cast To | Convert a reference to a specific class |
| Get/Set Variable | Read or write a Blueprint variable |
| Print String | Debug text on screen |
๐ฆ C++ Variables & UPROPERTY
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 Health = 100;
UPROPERTY(EditDefaultsOnly, Category="Stats")
float MoveSpeed = 600.f;
UPROPERTY(VisibleAnywhere)
bool bIsAlive = true;
EditAnywhere exposes a variable in the Details panel. BlueprintReadWrite lets Blueprints read and write it.
๐ Flow Control (Blueprint & C++)
// C++ if/else
if (Health <= 0)
{
Destroy();
}
else if (Health < 20)
{
UE_LOG(LogTemp, Warning, TEXT("Low HP!"));
}
// loop over actors
for (AActor* Enemy : Enemies)
{
Enemy->Destroy();
}
In Blueprints: use a Branch node for if/else and a For Each Loop node for arrays.
๐ก Events, Delegates & Dispatchers
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(
FOnHealthChanged, int32, NewHealth);
UPROPERTY(BlueprintAssignable)
FOnHealthChanged OnHealthChanged;
void ATD ::TakeDamage(int32 Amount)
{
Health -= Amount;
OnHealthChanged.Broadcast(Health);
}
In Blueprints, use Custom Events and Event Dispatchers (Bind/Call) for the same one-to-many pattern.
๐ฎ Enhanced Input
// C++ setup (Pawn/Character)
void APlayerPawn::SetupPlayerInputComponent(
UInputComponent* PlayerInputComponent)
{
UEnhancedInputComponent* EIC =
Cast(PlayerInputComponent);
EIC->BindAction(MoveAction, ETriggerEvent::Triggered,
this, &APlayerPawn::Move);
EIC->BindAction(JumpAction, ETriggerEvent::Started,
this, &APlayerPawn::Jump);
}
In Blueprints: add an Input Mapping Context in BeginPlay, then use Enhanced Input Action event nodes.
๐ณ Actors & Components
| AActor | Base class for anything placed in a level |
| APawn / ACharacter | Controllable actors (Character adds movement) |
| UStaticMeshComponent | Renders a static mesh |
| USkeletalMeshComponent | Renders an animated mesh |
| UCapsuleComponent | Common collision shape for characters |
| UCameraComponent | Defines the player's view |
| USpringArmComponent | Smooth camera boom/follow arm |
โฑ๏ธ Timers & Delays
// C++ delayed call
GetWorldTimerManager().SetTimer(
TimerHandle, this, &AMyActor::Respawn, 2.0f, false);
// Loop every second
GetWorldTimerManager().SetTimer(
TickHandle, this, &AMyActor::Tick1s, 1.0f, true);
In Blueprints: use a Delay node for a one-off wait, or Set Timer by Function Name for repeating calls.
๐ ๏ธ Handy Snippets & Patterns
// Open a level
UGameplayStatics::OpenLevel(this, FName("Level_2"));
// Random number / pick
int32 Roll = FMath::RandRange(1, 6);
// Spawn an actor
FActorSpawnParameters Params;
GetWorld()->SpawnActor(EnemyClass, SpawnTransform, Params);
// Cast a hit actor
if (AEnemy* Enemy = Cast(Hit.GetActor()))
{
Enemy->TakeDamage(10);
}
// Get player controller / pawn
APlayerController* PC = UGameplayStatics::GetPlayerController(this, 0);