October 24, 2024

UE Architecture


This is why you should not write any gameplay code in the constructor:

UHT generates the code for each class and struct marked with UCLASS and USTRUCT macros. One of the feature it gives us is CDO - class default object. UE creates a default object of each class for using it as a template and runs it's own contstructor. So, be sure you have just initialization code in the class/struct constructors.


UE Main Loop:

UE main loop is designed in the GEngineLoop class. It consits of 4 stages:

  1. Preinit():
  2. Init():
  3. Tick():
  4. Exit():

GEngineLoop.Preinit():

  • Loades project, plugins and modules
  • Creates CDOs and structures marked with UCLASS and USTRUCT macros.
  • After UE registers all classes, it will call the StartupModule() function for every module (Module initialization)

GEngineLoop.Init():

  • Creates the instance of UEngine class (base class for UEditorEngine and UGameEngine classes )
  • Initializes UEngine instance. This creates GameInstance, GameViewportClient and LocalPlayer instances.
  • Browses to URL (Server), loades the Map and startes the Game.
  • LoadMap() function:
    • Creates UWorld, ULevel, Actors saved to Levels and ActorComponents defined in that Actors
    • Creates Core Actors:AGameModeBase, AGameSession, AGameStateBase, AGameNetworkManager, APlayerController, APlayerState, APawn
    • Initializes all Actors and Actor Components
    • BeginPlay(). Registers all actors tick functions

There are 2 different lifetimes at the high-level:

  1. Loaded before Map loaded: Engine Objects
  2. Loaded after Map loaded: Game Objects

GEngineLoop.Tick():

GEngineLoop.Exit():


ULocalPlayer

Representing the player sitting in front of the screen.

UGameViewportClient

Screen itself. High-level interface for rendering, audio and input systems. Represents the interface between the user and the Engine.

UGameInstance

Project-specific functionality what was before UE4.4 implemented in the GEngine class.

.umap

Serialized map data (UPackage) what contains: levels, actors, actors' components.

UPackage is the Outer of CDOs!


Actor->PostInitializeComponents() is the most earliest stage when the actor is already in the full-formed state.

AGameModeBase

SERVER-ONLY. Defines the rules of the game and spawns most of the core gameplay Actors. It's the ultimate authority.

AGameSession

SERVER-ONLY. For online games approves the login request. Serves as an interface to the Online Service (like Steam).

AGameNetworkManager

SERVER-ONLY. Configures things like cheat detection and movement prediction.

AGameStateBase

SERVER-AUTHORITATIVE, but replicated to all clients! Can be changed just by server. Stores game state data all player should know about.

  • There are 2 representations of the player:

  • PlayerController and PlayerState classes representation is similar to GameMode and GameState.