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:
- 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)
- 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:
Representing the player sitting in front of the screen.
Screen itself. High-level interface for rendering, audio and input systems. Represents the interface between the user and the Engine.
Project-specific functionality what was before UE4.4 implemented in the GEngine class.
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.
SERVER-ONLY. Defines the rules of the game and spawns most of the core gameplay Actors. It's the ultimate authority.
SERVER-ONLY. For online games approves the login request. Serves as an interface to the Online Service (like Steam).
SERVER-ONLY. Configures things like cheat detection and movement prediction.
SERVER-AUTHORITATIVE, but replicated to all clients! Can be changed just by server. Stores game state data all player should know about.