Unreal Engine: code architecture¶
How to structure C++ and Blueprint gameplay code, data, input, UI and multiplayer so that it stays changeable as the project grows.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 Gameplay Framework (Unreal Engine documentation): the baseline for gameplay code. What the game instance, game mode, game state, player state, controllers and pawns are for, and how they relate.
- 9 Epic C++ Coding Standard: naming, class layout, formatting and C++ language rules. Mandatory at Epic.
- 8 Networking Overview: the client-server model, replication, RPCs, network roles and a list of networking tips.
- 8 Exposing C++ to Blueprints: when to use C++ or Blueprint, and how to design a Blueprint-friendly C++ API.
- 6 Blueprint Best Practices: Level Blueprints versus Blueprint classes, functions versus macros, and communication between Blueprints.
Key rules¶
Code and gameplay framework¶
- 9
UNREAL-1Hold UObject references that must keep their target alive inUPROPERTYmembers, preferablyTObjectPtr, and useTWeakObjectPtrfor references that must not. The garbage collector can't see raw pointers, so their targets can be collected and the pointers left dangling. (Unreal Object Handling, Object Pointers) - 8
UNREAL-2Put match rules in the game mode, which exists only on the server, state that all players need in the game state, per-player state in the player state, and anything that must survive a level change in the game instance or its subsystems. (Gameplay Framework, Game Mode and Game State) - 7
UNREAL-3Write core systems, high-frequency logic and data-heavy work in C++ base classes, and expose a small API that designers extend in Blueprint subclasses. Move a Blueprint's logic into C++ when profiling or its complexity calls for it. (Exposing C++ to Blueprints, Blueprint Best Practices) - 7
UNREAL-4Put game-wide services in subsystems (UGameInstanceSubsystem,ULocalPlayerSubsystem,UEngineSubsystemorUEditorSubsystem) instead of adding them to a custom game instance or overriding engine classes. (Programming Subsystems) - 7
UNREAL-23Don't poll for changes on Tick: run occasional logic from events, delegates or timers, give logic that must repeat but not every frame a tick interval, and turn ticking off on Actors and components that don't need it. Spread expensive work, such as spawning many Actors, over several frames, and move heavy computation off the game thread with the Tasks System rather than your own threads. (Unreal Engine, Common Memory and CPU Performance Considerations, Actor Ticking, Gameplay Timers, Tasks System) - 5
UNREAL-24Represent statuses, object types and gameplay events as hierarchical Gameplay Tags of the formMovement.Mode.Swimming, registered in.initag lists or as native tags in C++. The Gameplay Ability System uses them to track each Actor's status. (Unreal Engine, Using Gameplay Tags, Understanding the Gameplay Ability System) - 5
UNREAL-6Use the Gameplay Ability System for games built around many abilities, attributes and status effects, especially multiplayer ones. It replicates abilities and attributes, and supports prediction. (Understanding the Gameplay Ability System) - 5
UNREAL-25Model AI and other state-driven logic, such as game flow, in StateTree, Epic's general-purpose hierarchical state machine, or, for AI, in Behavior Trees with a Blackboard. This appliesGAMEDEV-21. (Unreal Engine, StateTree Overview, Behavior Trees)
Data and save games¶
- 7
UNREAL-26Put designer-tunable data in Data Tables, whose rows are C++ structs and which designers can import from CSV or JSON files, or in Data Assets, and make content that the Asset Manager loads on demand a Primary Data Asset. This appliesGAMEDEV-3. (Unreal Engine, Data Driven Gameplay Elements, Asset Management) - 7
UNREAL-27Save games through your ownUSaveGamesubclasses, with separate classes for globally unlocked features and for each playthrough's data, and save withAsyncSaveGameToSlotduring play. Epic recommends asynchronous saving because it avoids a frame-rate hitch and a possible certification issue on some platforms. Versioning and keeping the last good save areGAMEDEV-10andGAMEDEV-11. (Unreal Engine, Saving and Loading Your Game)
Blueprints, input and UI¶
- 6
UNREAL-28Choose how Blueprints communicate by the relationship between them: a direct reference for one Actor talking to one specific other, an event dispatcher to tell any number of listeners that something happened, and a Blueprint Interface to call the same function on unrelated classes that each respond in their own way. (Unreal Engine, Blueprint Communication Usage, Blueprint Interface) - 6
UNREAL-29Handle player input with Enhanced Input: an Input Action for each thing the player can do, Input Mapping Contexts that you add, remove and prioritize as the player's situation changes, and Player Mappable Input Configs for control presets. Enhanced Input is on by default, and it supports remapping controls at run time, which is part ofGAMEDEV-18. (Unreal Engine, Enhanced Input) - 5
UNREAL-30Keep game logic out of UMG widgets: give widgets their data through viewmodels and View Bindings (the UMG Viewmodel plugin, in Beta), which update a widget only when a value changes, and set the Property Binding Rule to Prevent so that nobody adds legacy property bindings. For layered menus that must work with a gamepad, build on the Common UI plugin. (Unreal Engine, UMG Viewmodel, Common UI Plugin)
Accessibility¶
- 5
UNREAL-45If players need a screen reader, turn on Unreal's accessibility support withAccessibility.Enable=1, set the Accessibility options of each UMG widget, such as Accessible Behavior, and choose how it's read: by third-party screen readers on Windows and VoiceOver on iOS, or by the Slate Screen Reader plugin, which reads focused Slate and UMG widgets aloud with the engine's text-to-speech. Epic marks screen reader support as Experimental, and the Text To Speech plugin supports only English, so test it on each target platform before you rely on it. This appliesA11Y-9. (Unreal Engine, Supporting Screen Readers, Unreal Engine, Blind Accessibility Features Overview)
Multiplayer¶
- 8
UNREAL-8Keep the server authoritative: clients request actions through Server RPCs, and the server validates them before it changes any state. (Networking Overview, Remote Procedure Calls, Game development: server authority) - 7
UNREAL-9Prefer replicated properties with RepNotify to RPCs, use multicast RPCs sparingly, and make frequently called RPCs unreliable. (Networking Overview, networking tips) - 4
UNREAL-31In games with many players and many replicated Actors, decide what each client receives with the Replication Graph, and evaluate Iris, which is still Experimental, before relying on it. The standard replication strategy checks every replicated Actor against every client, which can bottleneck the server's CPU. (Unreal Engine, Replication Graph, Iris Replication System)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 6 UMG Viewmodel, Property Binding Rule: set to Prevent in Project Settings > Editor > Widget Designer (Team), it removes the option to add legacy property bindings in the Widget Designer. Partly checks
UNREAL-30. - 5 PVS-Studio V1100: flags pointers to UObject types held in classes that don't derive from
UObject, where the garbage collector can't see them. It's a commercial analyser that Unreal Build Tool runs with-StaticAnalyzer=PVSStudio. Partly checksUNREAL-1.