U Code

Related notes: Unreal Blueprint Code

Unreal

Dont mix logic and assets ! Unreal CPP Guide https://youtu.be/IaU2Hue-ApI

Project Environment Setup

  • Download from Epic Games Launcher - Provides non-editable code for your project.
  • Download from GitHub - Includes source code for customization:
    • Add the GitHub repository to Unreal Engine.
    • Set up associations for the project.
    • Use GameSync for project management, which requires building the project.

Folder structure

  • Config, Content, Source, .uproject
  • Optionally, Binaries

Config File Hierarchy - Allows overriding default engine settings:

  1. Engine/Config - Base .ini files for editor settings.
  2. Engine/*PlatformFolders*/Config - Platform-specific .ini files.
  3. Project/Config - Default*.ini files for project-specific settings.
  4. Project/*PlatformFolders*/Config - Platform-specific project settings.
  5. Project/Saved/*PlatformFolders*/Config - Runtime-generated configuration files.
    • Intermediate - Contains compilable files, can be deleted when syncing, not typically version controlled.
    • Project/Bin:
    • Contains built modules with .pdb files for debug symbols.
    • exec files compiled by the build tool. - Engine/Binaries/DotNET/ - Contains Swarm agent for distributed builds. - Engine/Binaries/Win64/ - Executable files for Windows. - Engine/Plugins - For adding functionality via plugins. - .uproject - Defines engine associations and lists modules/plugins for the project.

Loading Process

  • Main Function (LaunchWindows.cpp):
    • Engine Loop (base gameplay loop)
      1. Pre-Init - Most modules are loaded here.
      2. Init - Initializes objects, sets up the player viewport, and associates with the game instance. Further initialization occurs during:
        • Load Map Call.
      3. Tick - Continuous game update cycle.

Engine structure

  • Source Code: Written in C++.
  • Modules: Collections of classes compiled into a single .dll, functioning like plugins.
  • Macros: Used to expose functions from C++ to Blueprints (BP) and the editor. Examples include UCLASS, USTRUCT, UENUM, UPROPERTY, which handle metadata, function exposure to BP, networking, and serialization.
  • Core Features:
    • Basic Types: https://youtu.be/0x65wBATCnU
      • Numbers: Float, Double, (U)Int8/16/32/64 (use explicit integer types for good programming habits).
      • List: Enum Defined in files, used as named variables.
      • Structure: Similar to classes but for plain data; can combine different data types (e.g., Transform includes location, rotation, scale).
      • Strings: FString (mutable), FName (fast, case-insensitive for names and paths), FText (for localization).
      • Collections: TSet (unordered set), TArray (array), TMap (key-value pairs, updates if key matches).
      • Vectors & Rotations: FVector, FRotator, FQuat.
      • UObject: Base class for memory management.
      • Actor: Can be placed in levels.
        • Components:
          • UActorComponent: No world transform.
          • USceneComponent: Has transform relative to parent actor.
    • Smart Pointers: Not detailed but important for memory management.
    • Interfaces: Preferably created in C++.
    • Static Functions.
    • Data Management: Data Assets, Data Tables, Curves.
    • Event System: Delegates and events.
    • Subsystems: For modular code organization.
    • Async Task Graph: For managing asynchronous operations.
  • Memory Management:
    • Assets load via maps or soft references, unloaded by garbage collector when no longer referenced or pending kill.
    • Hard references load all related assets; prefer soft references to avoid unnecessary loading.
    • Garbage Collection uses mark-and-sweep, optimized for multithreading.
  • Replication: Supports networking for up to 100 players.

Gameplay Framework

In object-oriented design, everything follows a hierarchical structure.

  • UObject - The primary class in C++, used by the engine for memory management.
    • AActor - A subclass of UObject, can be spawned in a scene.
      • APawn - A subclass of AActor, can be possessed by a controller.
        • ADefaultPawn - A basic pawn class for default implementations.
        • ACharacter - Specialized subclass of APawn for anthropomorphic figures like humans.
  • Game Mode - Defines the rules of the game, what to spawn at the start, and session rules for multiplayer. Not suited for storing persistent data.
  • Game Instance - Manages persistent data accessible across the game.
  • Game State - Manages the state of the game that can be replicated to all players.
  • Pawn - Defines how a character moves, looks, and interacts.
    • Set DefaultPawnClass in the game mode constructor or override AGameModeBase::GetDefaultPawnClassForController.
  • Character - A specialized pawn with:
    • A capsule component for collision.
    • Character movement component linked to the character class.
    • Skeletal mesh for visual representation.
    • Capabilities like replication, pathfinding, and root motion from animation playback.
  • Player State - Holds data relevant to a player’s standing in the game (e.g., name, score), how they’re represented to others.
    • Set PlayerStateClass in the game mode constructor or override AController::InitPlayerState.
  • Player/AI Controller - Manages server-authoritative data and local state for the owning player, handles input and UI.
    • Set PlayerControllerClass in the game mode constructor or override AGameModeBase::SpawnPlayerController.
  • Input Component - Manages input, with enhancements in newer versions.
  • Movement Component - Handles movement for pawns, vehicles, etc.
  • Cheat Management - For implementing cheat codes or admin commands.
  • Ticks - Regular updates for game logic, physics, etc.
  • Mass - Affects physics like gravity and motion.
  • Game Features Plugins - Can be loaded at runtime to extend gameplay features.

Data management

Data Management

Questions to Ask:

  • Where to store data? How will be edited? Is scalability available? How does versioning work? How are saves managed? Support for multiple languages? What about data validation? When is data loaded? Can data be broken into parts for better management?

  • Blueprints - Offers easy validation and bulk editing via property matrix. Use soft asset references for assets not actively in use to manage memory.
  • Data Assets - Requires opening the editor to edit. Can store data in a single asset, but editing might be less straightforward than with data tables.
  • Data Tables - Preferably the master for data management. Loads all data at once, ideal for working in one place. Supports CSV/JSON imports, allowing for external editing by those with the capability.
  • Data Registry - A newer feature, similar to composite data tables, useful for collaborative work where multiple people edit data.
  • Curves - For defining data that changes over time or with parameters, like animations or gameplay stats.

Dependencies

  • Loading assets in a chain can have significant performance implications. It’s challenging to break data into parts because everything is interconnected, sometimes leading to memory issues.
  • Casting to a specific type can inadvertently create hard references, increasing memory usage. Always check with the Asset Manager.

Debugging:

  • Run ‘Size Map’ on an asset to analyze its memory footprint and dependencies.

Build

Unreal Build tool

Generate project files.

  • Native project: engine in same root as project let asociate proj&engine
  • compile from IDE () or unreal editor itself. or unreal game sync or live ++
  1. if contain C++ code you must build your binaries first.
    • target : - editor client …
    • state : - debug includ symbols

Unreal automation tool

If u want to pack

  1. cookig - optimised files per platform
    • cook by the book
    • cook on the fly - cook will skip (increas loading but faster itters)
  2. staging - copies
  3. packing (save coocked)
  4. Run…
  5. Gauntlet - automation tests.

Team City

#Engine loop

Learning materials

learn form begin epic
https://www.unrealdirective.com/
https://youtu.be/IaU2Hue-ApI

`get player` jest tym samym co `get player character > Cast to Generic Character [convert to pure cast] `