๐ฎ Blueprint Nodes
// Core lifecycle
Event BeginPlay - runs once on spawn
Event Tick - runs every frame
Event Any Damage - receives damage
// Actor spawning & control
Get Player Character - reference to player
Get Player Controller - player controller ref
Spawn Actor from Class - spawn an actor
Destroy Actor - remove from world
// Transform
Set Actor Location - move to vector
Get Actor Location - current world pos
// Movement
Add Movement Input - push movement dir
Get Forward Vector - actor forward dir
๐ฆ C++ Classes
| AActor | Base spawnable object in the world |
| APawn | Actor that can be possessed by a controller |
| ACharacter | Pawn with CharacterMovementComponent built in |
| APlayerController | Handles player input and HUD |
| AGameModeBase | Server-side rules, spawning, game state |
| UActorComponent | Non-attached reusable component |
| USceneComponent | Component with transform (position, rotation) |
๐ท๏ธ UPROPERTY Specifiers
| EditAnywhere | Editable in any Details panel |
| BlueprintReadWrite | Read & write from Blueprints |
| VisibleAnywhere | Visible but not editable in Details |
| Category | Group properties in panel sections |
| meta=(ClampMin) | Minimum allowed value for numerics |
| meta=(ClampMax) | Maximum allowed value for numerics |
UPROPERTY(EditAnywhere, Category="Stats")
float Health = 100.f;
UPROPERTY(BlueprintReadWrite, meta=(ClampMin="0", ClampMax="100"))
float Speed = 600.f;
โก UFUNCTION Specifiers
| BlueprintCallable | Can be called from Blueprints |
| BlueprintPure | No side effects, no exec pin needed |
| BlueprintImplementableEvent | Override in Blueprint only |
| BlueprintNativeEvent | Override in C++ or Blueprint |
UFUNCTION(BlueprintCallable)
void TakeDamage(float Amount);
UFUNCTION(BlueprintPure)
float GetHealthPercent() const;
UFUNCTION(BlueprintNativeEvent)
void OnDeath();
void OnDeath_Implementation();
๐ Movement
// CharacterMovementComponent (built into ACharacter)
GetMovementComponent() - access CMC
// Movement input
AddMovementInput(GetActorForwardVector(), 1.0f);
// Jumping
Jump() - initiate jump
StopJumping() - stop jump early
// In C++
CharacterMovement->MaxWalkSpeed = 600.f;
CharacterMovement->GravityScale = 1.5f;
CharacterMovement->JumpZVelocity = 420.f;
CharacterMovement->AirControl = 0.2f;
๐ฏ Input (Enhanced Input)
// Assets needed
InputAction - defines an action
InputMappingContext - maps keys to actions
// In C++ (BeginPlay)
EnhancedInput->BindAction(
IA_Move, ETriggerEvent::Triggered,
this, &AMyCharacter::Move);
// Reading input value
void Move(const FInputActionValue& Value) {
FVector2D Input = Value.Get<FVector2D>();
AddMovementInput(GetActorForwardVector(), Input.Y);
AddMovementInput(GetActorRightVector(), Input.X);
}
// BindAction in Enhanced Input
BindAction(IA_Jump, ETriggerEvent::Started,
this, &ACharacter::Jump);
BindAction(IA_Jump, ETriggerEvent::Completed,
this, &ACharacter::StopJumping);
๐ฅ Collision
// Overlap callbacks (C++)
OnComponentBeginOverlap(Component, OtherActor,
OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
OnComponentEndOverlap(Component, OtherActor,
OtherComp, OtherBodyIndex);
// Hit callback
OnHit(HitComponent, OtherActor, OtherComp,
NormalImpulse, Hit);
// Line trace (C++)
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);
LineTraceSingleByChannel(
HitResult, Start, End,
ECC_Visibility, Params);
๐ Math Types
| FVector | 3D vector: FVector(X, Y, Z) |
| FRotator | Rotation: FRotator(Pitch, Yaw, Roll) |
| FTransform | Position + rotation + scale combined |
| FMath::Lerp | Linear interpolation between two values |
| FMath::Clamp | Clamp value between min and max |
| FMath::Sqrt | Square root of a value |
| FMath::Atan2 | Angle from Y and X components |
// Common usage
FVector Pos = GetActorLocation();
FVector Dir = Target - Pos;
float Dist = Dir.Size();
FVector Norm = Dir.GetSafeNormal();
float Speed = FMath::Lerp(0.f, MaxSpeed, Alpha);
float Val = FMath::Clamp(Val, 0.f, 1.f);
๐จ UI (UMG)
| UUserWidget | Base class for all UMG widgets |
| UButton | Clickable button widget |
| UTextBlock | Text display widget |
| UImage | Image display widget |
| AddToViewport() | Show widget on screen |
| RemoveFromParent() | Hide / destroy widget |
// Create and show HUD (C++)
UUserWidget* HUD = CreateWidget<UUserWidget>(
GetWorld(), HUDClass);
HUD->AddToViewport();
// Hide
HUD->RemoveFromParent();
// Blueprint: Create Widget โ Add to Viewport
๐ ๏ธ Common Patterns
โโ PLAYER CONTROLLER SETUP โโ
void AMyGameMode::BeginPlay() {
Super::BeginPlay();
DefaultPawnClass = AMyCharacter::StaticClass();
PlayerControllerClass = AMyPlayerController::StaticClass();
}
โโ ENEMY AI โโ
void AEnemy::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
FVector Dir = Player->GetActorLocation() - GetActorLocation();
Dir.Z = 0;
AddMovementInput(Dir.GetSafeNormal(), 1.0f);
}
โโ HEALTH SYSTEM โโ
void AMyCharacter::TakeDamage(float Amount) {
Health = FMath::Clamp(Health - Amount, 0.f, MaxHealth);
if (Health <= 0.f) OnDeath();
}
โโ SPAWN ACTOR โโ
FActorSpawnParameters Params;
Params.Owner = this;
GetWorld()->SpawnActor<AProjectile>(
ProjectileClass, MuzzleLoc, MuzzleRot, Params);
โโ SAVE GAME โโ
USaveGame* Save = CreateObject<USaveGame>();
UGameplayStatics::SaveGameToSlot(Save, "Slot1", 0);
UGameplayStatics::LoadGameFromSlot("Slot1", 0);
โโ CAMERA FOLLOW โโ
void AMyCharacter::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
FVector Target = GetActorLocation();
FVector CamLoc = FVector(Target.X, Target.Y, Target.Z + 500.f);
SpringArm->SetWorldLocation(
FMath::Lerp(SpringArm->GetComponentLocation(), CamLoc, DeltaTime * 5.f));
}