iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Unreal Engine

Unreal Engine 5 is the industry workhorse for high-fidelity games — Lumen lighting, Nanite geometry, MetaHumans, and the Blueprint+C++ split. Knowing the project structure, Actor/Component model, and how to bridge Blueprint and code is how you get started without drowning.

Project, Actors, Blueprints, C++ bridge

EXAMPLE
// 1) Install
// Epic Games Launcher → Library → Engine Versions → Install Unreal Engine 5.4+
// Pick the latest stable; 5.4 introduced Game Animation Sample and Motion Matching.
// Source builds (clone EpicGames/UnrealEngine + Visual Studio) needed for engine modifications.

// 2) Project anatomy
//   MyGame.uproject       — JSON manifest: engine version, plugins, modules
//   Config/                — DefaultEngine.ini, DefaultGame.ini, DefaultInput.ini
//   Content/                — assets (Blueprints, materials, levels) — large binary files
//   Source/                 — C++ code
//       MyGame/             — primary module (.h, .cpp, .Build.cs)
//       MyGame.Target.cs    — build target for the game
//       MyGameEditor.Target.cs — build target for editor
//   Plugins/                — drop-in plugins (game-specific + third-party)
//   Binaries/                — generated
//   Intermediate/           — generated; safe to delete to force rebuild
//   Saved/                   — logs, autosaves, screenshots — don't commit

// 3) Actors + Components — the core mental model
// • Actor = anything that can be placed in a level (character, light, camera, trigger)
// • Components = behaviour/data attached to Actors (StaticMeshComponent, AudioComponent, custom)
// • An Actor's components form a hierarchy with one root
// • Levels = collections of Actors; usually streamed via World Partition in UE5

// 4) Spawning an Actor in C++ — header file
// MyGame/Source/MyGame/PickupActor.h
#pragma once
#include 'CoreMinimal.h'
#include 'GameFramework/Actor.h'
#include 'PickupActor.generated.h'

UCLASS(Blueprintable)
class MYGAME_API APickupActor : public AActor {
    GENERATED_BODY()
public:
    APickupActor();

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
    class UStaticMeshComponent* Mesh;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = 'Pickup')
    int32 ScoreValue = 10;

    UFUNCTION(BlueprintCallable, Category = 'Pickup')
    void Collect(class APlayerController* Collector);

    UFUNCTION(BlueprintImplementableEvent, Category = 'Pickup')
    void OnCollected();    // implemented in Blueprint subclass

protected:
    virtual void BeginPlay() override;
    virtual void Tick(float DeltaSeconds) override;
};

// PickupActor.cpp
#include 'PickupActor.h'
#include 'Components/StaticMeshComponent.h'

APickupActor::APickupActor() {
    PrimaryActorTick.bCanEverTick = true;
    Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT('Mesh'));
    RootComponent = Mesh;
}

void APickupActor::BeginPlay() {
    Super::BeginPlay();
}

void APickupActor::Tick(float DeltaSeconds) {
    Super::Tick(DeltaSeconds);
    AddActorLocalRotation(FRotator(0.f, 60.f * DeltaSeconds, 0.f));
}

void APickupActor::Collect(APlayerController* Collector) {
    OnCollected();    // give Blueprint a chance to react
    Destroy();
}

// 5) UPROPERTY / UFUNCTION macros — the engine uses these for serialisation + reflection
// • UPROPERTY()       — make a property visible to editor / Blueprint / GC
// • UFUNCTION()       — expose a function to Blueprint / network
// • Categories appear in the Details panel
// • BlueprintImplementableEvent — declared in C++, body in Blueprint
// • BlueprintNativeEvent          — has a default C++ body, overridable in Blueprint

// 6) Blueprints — visual scripting
// • Right-click PickupActor in the Content Browser → Create Blueprint Class based on it
// • Override OnCollected to play a Niagara particle, add a Sound, modify a score variable
// • Designers iterate in Blueprint; engineers harden the hot paths in C++ later

// 7) Communicating between Blueprint and C++
// • C++ -> Blueprint: BlueprintImplementableEvent, dispatchers (multicast delegate calls)
// • Blueprint -> C++: UFUNCTION(BlueprintCallable)
// • Variables flow both ways via UPROPERTY(BlueprintReadWrite)

// 8) Input handling (Enhanced Input — UE5 modern path)
// • Create InputAction assets (IA_Jump, IA_Move) + InputMappingContext asset
// • In PlayerController/Character, add the context and bind handlers:
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* Comp) {
    Super::SetupPlayerInputComponent(Comp);
    auto* EI = CastChecked<UEnhancedInputComponent>(Comp);
    EI->BindAction(IA_Move, ETriggerEvent::Triggered, this, &AMyCharacter::Move);
    EI->BindAction(IA_Jump, ETriggerEvent::Started,   this, &AMyCharacter::Jump);
}

void AMyCharacter::Move(const FInputActionValue& Value) {
    const FVector2D Axis = Value.Get<FVector2D>();
    AddMovementInput(GetActorForwardVector(), Axis.Y);
    AddMovementInput(GetActorRightVector(),   Axis.X);
}

// 9) Lumen + Nanite — UE5 headline features
// • Lumen: dynamic global illumination + reflections — enable in Project Settings → Rendering
// • Nanite: virtualised geometry; import massive meshes without LOD authoring (statics only; skeletals are catching up)
// • Both need DX12 or Vulkan; older GPUs fall back to Lumen Hardware Ray Tracing or Software Lumen

// 10) World Partition + Data Layers — open-world level streaming
// • World Partition replaces World Composition; auto-streams cells around the camera
// • Data Layers gate Actor visibility (e.g. 'inside vs outside' or 'day vs night')
// • One Level Asset, many cells, faster iteration than the old persistent + sub-level model

// 11) Common subsystems
// • GameInstance — persistent for the whole session (settings, save game pointer)
// • GameMode      — rules; only exists on the server
// • GameState     — replicated game-wide data (score, time remaining)
// • PlayerController — per-player; input handling, HUD, camera
// • Pawn / Character — what the player drives
// • HUD / Widgets — UI (UMG = Slate-backed)

// 12) Networking — replication
// UE has a built-in client/server model with RPCs and replicated properties.
//   UPROPERTY(Replicated)         FVector ServerLocation;
//   UFUNCTION(Server, Reliable)   void Server_RequestFire();
//   UFUNCTION(NetMulticast)       void Multicast_PlayHit();
//
// • Authoritative server prevents cheating
// • Use rollback / lag compensation for fast-paced shooters
// • Listen Server for prototyping; dedicated servers for production

// 13) Animation
// • Animation Blueprint — state machine + blend spaces (idle, walk, run, jump)
// • Control Rig + Sequencer for cinematics
// • Motion Matching (UE5.4+) — picks animations to match desired motion; less curated than state machines

// 14) Plugins to know
// • Game Animation Sample (free, official) — drop-in third-person Motion Matching character
// • MetaHumans — photorealistic characters; Quixel Bridge integration
// • Lyra — sample multiplayer game; great reference for modular game features
// • Niagara — particles + VFX
// • Sequencer — cinematic editing
// • Editor Utility Widgets — custom editor tooling without rebuilding the editor

// 15) Performance + profiling
// • Stat Unit / Stat GPU / Stat Game — overlay frame breakdown
// • Unreal Insights — capture .utrace; deep timeline view
// • Visualize -> Light Complexity / Shader Complexity — find expensive shaders
// • Niagara overdraw + Lumen scene complexity views
// • Pak file loading — package game then profile via stat LoadTimeData

// 16) Version control
// • Git LFS for binary content (.uasset / .umap > 100MB at scale)
// • Perforce is industry standard for big teams
// • UE supports both natively; use 'Source Control' panel inside the editor
// • Use locking on .uasset files — they're binary and don't merge

// 17) Build + ship
// • File → Package Project → pick platform (Windows, Mac, Linux, Android, iOS, consoles)
// • Use a Build Configuration of 'Shipping' or 'Test' (not 'Development') for end-user builds
// • UnrealAutomationTool (UAT) for CI builds
// • Steamworks / Epic Online Services plugins for the storefront tie-ins

// 18) Common bugs
// • Forgot GENERATED_BODY() — class won't compile or won't appear in the editor reflection system
// • Edited a UPROPERTY without recompiling Live Coding — values reset on next play
// • Crash on .uasset reference — likely a circular reference or deleted asset; check Output Log
// • Garbage collection eats your Actor — keep a UPROPERTY() reference, never a raw pointer in long-lived objects
// • Networking: forgot DOREPLIFETIME for a Replicated property → never replicates
// • Lumen looks black — check that Generate Lightmap UVs is off for Nanite meshes; lumen handles GI dynamically
// • Editor crashes opening a Blueprint — likely a corrupt asset; check Saved/Crashes for the call stack
// • 'No tracked git changes' on a binary asset edit — Git LFS not initialised; binary diff blew up the repo

Why it matters

Unreal mixes C++ and Blueprints by design — write systems in C++, expose properties and events with UPROPERTY/UFUNCTION, and let designers iterate in Blueprint. Reach for World Partition + Lumen + Nanite for open-world fidelity, Enhanced Input for controls, and the Lyra sample as a reference architecture for multiplayer game features.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// Unreal: Blueprints (visual) or C++.
// Tip: prototype with Blueprints; promote hot code paths to C++.
Try it Yourself »

Discussion

Loading…