Blueprint Design Patterns & Clean Code โ
๐ฏ Overview โ
Modern Blueprint development requires disciplined patterns and clean code principles. This guide covers industry-standard approaches for creating maintainable, scalable Blueprint systems using DRY, KISS, and SOLID principles adapted for visual scripting.
Clean Code Architecture Flow โ
graph TB
subgraph "SOLID Principles"
S[Single Responsibility]
O[Open/Closed]
L[Liskov Substitution]
I[Interface Segregation]
D[Dependency Inversion]
end
subgraph "DRY Implementation"
FL[Function Libraries]
IF[Interface Abstraction]
CO[Component Reuse]
end
subgraph "KISS Approach"
SR[Single Responsibility]
CF[Clear Flow]
SM[Simple Methods]
end
S --> FL
O --> IF
I --> CO
FL --> SR
IF --> CF
CO --> SM
style S fill:#e8f5e8
style FL fill:#f3e5f5
style SR fill:#e3f2fd๐งฑ Core Design Principles โ
DRY (Don't Repeat Yourself) โ
Eliminate duplication through smart Blueprint architecture.
Function Libraries Pattern โ
๐น Create Blueprint Function Libraries for:
โข Math utilities (distance calculations, interpolations)
โข String formatting and validation
โข Array/Map manipulation helpers
โข Common gameplay calculations
โข UI state management functionsInterface-Based Abstraction โ
๐น Blueprint Interface: IInteractable
โข Function: Interact(Actor Instigator)
โข Function: GetInteractionText() -> Text
โข Function: CanInteract(Actor Instigator) -> Bool
๐น Implementation across multiple actors:
โข BP_Door implements IInteractable
โข BP_Chest implements IInteractable
โข BP_NPC implements IInteractableComponent-Based Reusability โ
๐น Create reusable components:
โข AC_Health (health management)
โข AC_Inventory (item storage)
โข AC_Interaction (interaction handling)
โข AC_AudioManager (sound effects)KISS (Keep It Simple, Stupid) โ
Favor clarity over cleverness in Blueprint design.
Single Responsibility Principle โ
โ Bad: One massive Blueprint handling:
โข Player movement
โข Combat system
โข Inventory management
โข UI updates
โข Audio management
โ
Good: Separate focused Blueprints:
โข BP_PlayerMovement
โข BP_CombatSystem
โข BP_InventoryComponent
โข BP_UIManager
โข BP_AudioComponentClear Node Flow โ
โ
Linear execution flow:
Input โ Validation โ Core Logic โ Output โ Cleanup
โ Avoid:
โข Excessive branching
โข Nested sequence chains
โข Complex multi-cast delegatesSOLID Principles for Blueprints โ
Single Responsibility โ
Each Blueprint should have one reason to change.
๐น BP_WeaponBase
โข Handles: Damage calculation, ammo management
โข Does NOT handle: Player input, UI updates, inventory
๐น BP_PlayerController
โข Handles: Input processing, camera control
โข Does NOT handle: Health management, inventory logicOpen/Closed Principle โ
Blueprints should be open for extension, closed for modification.
๐น Create BP_WeaponBase with virtual functions:
โข FireWeapon() [Virtual]
โข ReloadWeapon() [Virtual]
โข GetDamage() [Virtual]
๐น Extend with specific weapons:
โข BP_Rifle extends BP_WeaponBase
โข BP_Pistol extends BP_WeaponBase
โข Override virtual functions as needed๐๏ธ Architectural Patterns โ
MVC Pattern for Blueprints โ
Model Layer โ
๐น Data-only Blueprints:
โข BP_GameData (pure data container)
โข BP_PlayerStats (statistics tracking)
โข BP_WorldSettings (configuration data)
๐น Characteristics:
โข No visual components
โข No input handling
โข Pure data structures and validationView Layer โ
๐น UI and Presentation:
โข BP_HUD (heads-up display)
โข BP_MainMenu (menu interface)
โข BP_InventoryWidget (inventory display)
๐น Characteristics:
โข Handles display only
โข Receives data from controllers
โข No direct game logicController Layer โ
๐น Logic Coordination:
โข BP_GameController (game flow management)
โข BP_PlayerController (player input coordination)
โข BP_UIController (UI state management)
๐น Characteristics:
โข Coordinates between Model and View
โข Handles business logic
โข Manages state transitionsObserver Pattern โ
Implement loose coupling through event-driven architecture.
Event Dispatcher System โ
๐น BP_EventManager:
โข OnPlayerHealthChanged(float NewHealth)
โข OnInventoryUpdated(TArray<FItemData> Items)
โข OnLevelComplete(int32 Score)
๐น Subscribers bind to relevant events:
โข UI elements listen to data changes
โข Audio systems respond to game events
โข Analytics track player actionsGameplay Tag Events โ
๐น Use Gameplay Tags for loose coupling:
โข GameplayTag: "Event.Player.LevelUp"
โข GameplayTag: "Event.Combat.WeaponSwitch"
โข GameplayTag: "Event.UI.MenuOpen"
๐น Components listen for specific tags
๐น Easy to add/remove listeners without code changesFactory Pattern โ
Centralized object creation with consistent initialization.
Actor Factory System โ
๐น BP_ActorFactory:
โข CreateEnemy(EnemyType Type) -> BP_EnemyBase
โข CreateWeapon(WeaponData Data) -> BP_WeaponBase
โข CreatePickup(ItemData Item) -> BP_PickupBase
๐น Benefits:
โข Consistent initialization
โข Easy to modify creation logic
โข Supports object pooling
โข Centralized spawn logic๐จ Visual Organization Patterns โ
Node Grouping Standards โ
Color Coding System โ
๐น Input Handling: Light Blue
๐น Core Logic: Default (White/Gray)
๐น Validation: Yellow
๐น Output/Results: Green
๐น Error Handling: Red
๐น Debug/Temporary: PurpleComment Block Structure โ
๐น Header Comments:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ INITIALIZATION โ
โ Setup all components and variables โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐น Section Comments:
โโ INPUT VALIDATION โโโโโโโโโโโโโโโโโโ
โ Check all inputs before processing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐น Function Comments:
// Calculate damage with armor reductionExecution Flow Layout โ
๐น Left-to-Right Flow:
Input โ Processing โ Validation โ Output
๐น Vertical Grouping:
โข Main execution path: Center
โข Error handling: Below main flow
โข Helper functions: Above main flow
โข Debug outputs: Right sideBlueprint Organization Hierarchy โ
Folder Structure โ
๐ Blueprints/
โโโ ๐ Core/ (Base classes, interfaces)
โ โโโ BP_GameModeBase
โ โโโ BPI_Interactable
โ โโโ BP_ActorBase
โโโ ๐ Player/ (Player-specific)
โ โโโ BP_Player
โ โโโ BP_PlayerController
โ โโโ BP_PlayerState
โโโ ๐ Gameplay/ (Game mechanics)
โ โโโ ๐ Combat/
โ โโโ ๐ Inventory/
โ โโโ ๐ Interaction/
โโโ ๐ UI/ (User interface)
โ โโโ ๐ HUD/
โ โโโ ๐ Menus/
โ โโโ ๐ Widgets/
โโโ ๐ Environment/ (World objects)
โ โโโ ๐ Interactables/
โ โโโ ๐ Hazards/
โ โโโ ๐ Props/
โโโ ๐ Utilities/ (Helper functions)
โโโ BP_MathLibrary
โโโ BP_StringUtils
โโโ BP_ArrayHelpersNaming Conventions โ
๐น Classes:
โข BP_ClassName (main Blueprint)
โข AC_ComponentName (Actor Component)
โข BPI_InterfaceName (Blueprint Interface)
โข E_EnumName (Enumerations)
โข S_StructName (Structures)
๐น Variables:
โข bIsValid (boolean)
โข iPlayerCount (integer)
โข fMovementSpeed (float)
โข sPlayerName (string)
โข aInventoryItems (array)
๐น Functions:
โข GetHealthPercentage()
โข SetPlayerState()
โข CalculateDamage()
โข OnPlayerDeath()๐ง Implementation Patterns โ
Validation Patterns โ
Input Validation Chain โ
๐น Standard validation sequence:
1. Null checks (IsValid nodes)
2. Range validation (clamp values)
3. State validation (check prerequisites)
4. Permission validation (can perform action)
5. Resource validation (sufficient resources)
๐น Early return on validation failure
๐น Clear error messages for debuggingDefensive Programming โ
โ
Always validate:
โข Object references before use
โข Array indices before access
โข Division by zero scenarios
โข Network authority before replication
โข Component existence before calling functionsError Handling Patterns โ
Graceful Degradation โ
๐น Example: Weapon System
โข Primary fire fails โ Switch to secondary
โข No ammo โ Play empty click sound
โข Invalid target โ Clear target and continue
โข Component missing โ Use default behaviorError Recovery System โ
๐น BP_ErrorHandler:
โข LogError(String Message, ESeverity Level)
โข TryRecoverFromError() -> Bool
โข NotifyPlayerOfError(String UserMessage)
โข ReportToAnalytics(FErrorData Data)Performance Patterns โ
Object Pooling โ
๐น BP_PoolManager:
โข GetFromPool(UClass ObjectClass) -> AActor
โข ReturnToPool(AActor Object)
โข PrewarmPool(UClass ObjectClass, int32 Count)
๐น Use for:
โข Projectiles
โข Particles
โข Audio sources
โข UI elementsLazy Loading โ
๐น Delay expensive operations:
โข Load assets only when needed
โข Initialize components on first use
โข Cache calculations after first computation
โข Stream in content based on proximityState Management Patterns โ
State Machine Implementation โ
๐น Enum-Based State Machine:
โข E_PlayerState: Idle, Moving, Attacking, Defending
โข Switch statement for state transitions
โข Validation before state changes
โข Entry/Exit actions for each state
๐น State Component Pattern:
โข AC_StateMachine component
โข Data-driven state definitions
โข Event-driven transitionsCommand Pattern โ
๐น BP_Command (Base Class):
โข Execute() [Virtual]
โข Undo() [Virtual]
โข CanExecute() -> Bool [Virtual]
๐น Specific Commands:
โข BP_MoveCommand
โข BP_AttackCommand
โข BP_InventoryCommand
๐น Command Queue:
โข Queue commands for delayed execution
โข Support for undo/redo systems
โข Network-safe command replication๐ Advanced Patterns โ
Dependency Injection โ
Reduce tight coupling through injection patterns.
Service Locator Pattern โ
๐น BP_ServiceLocator:
โข RegisterService(UClass ServiceClass, UObject Service)
โข GetService(UClass ServiceClass) -> UObject
โข UnregisterService(UClass ServiceClass)
๐น Example Services:
โข Audio Service
โข Save System Service
โข Analytics Service
โข Input ServiceInterface Injection โ
๐น Inject dependencies through interfaces:
โข IHealthSystem for health management
โข IInventorySystem for item handling
โข IAudioSystem for sound management
๐น Components request interfaces, not concrete classes
๐น Easy to swap implementations for testingData-Driven Design โ
Use data assets for flexible, designer-friendly systems.
Configuration Pattern โ
๐น Data Assets for Configuration:
โข DA_WeaponConfig (damage, range, fire rate)
โข DA_PlayerConfig (movement speed, health)
โข DA_LevelConfig (spawn points, objectives)
๐น Runtime Modification:
โข Designers can tweak without Blueprint changes
โข A/B testing support
โข Mod support through data asset replacementTable-Driven Logic โ
๐น Data Tables for Complex Logic:
โข DT_DamageCalculation (armor vs weapon type)
โข DT_LootTables (item drop probabilities)
โข DT_DialogueOptions (conversation trees)
๐น Benefits:
โข Non-programmers can modify behavior
โข Easy to balance and iterate
โข Supports localizationNetwork Patterns โ
Clean patterns for multiplayer Blueprint development.
Authority Validation โ
๐น Network Authority Checks:
โข Server: Authoritative logic
โข Client: Prediction and visual feedback
โข Multicast: Synchronized visual effects
๐น Pattern:
if (HasAuthority()) {
// Execute authoritative logic
MulticastVisualEffect();
}Replication Patterns โ
๐น Replicated Variables:
โข Mark important state as replicated
โข Use RepNotify for client responses
โข Minimize replicated data size
๐น RPC Patterns:
โข Client-to-Server: Input and requests
โข Server-to-Client: Confirmations and updates
โข Multicast: Shared visual/audio effects๐ Best Practices Checklist โ
Before Creating New Blueprint โ
- [ ] Check if existing Blueprint can be extended
- [ ] Identify single responsibility for the Blueprint
- [ ] Plan interface requirements
- [ ] Consider component-based approach
During Development โ
- [ ] Use descriptive names for all nodes
- [ ] Group related nodes with comments
- [ ] Validate all inputs before processing
- [ ] Implement error handling paths
- [ ] Add debug output nodes for testing
Code Review Checklist โ
- [ ] DRY: No repeated logic across Blueprints
- [ ] KISS: Complex flows are broken into functions
- [ ] Clear execution flow (left-to-right)
- [ ] Proper error handling
- [ ] Performance considerations addressed
- [ ] Network authority properly handled
- [ ] Memory management considered
Refactoring Indicators โ
- [ ] Blueprint has more than 50 nodes
- [ ] Similar logic exists in multiple places
- [ ] Complex nested branches (>3 levels)
- [ ] Difficult to understand execution flow
- [ ] Performance issues during profiling
๐ฏ Common Anti-Patterns to Avoid โ
The God Blueprint โ
โ Problem: One Blueprint handling everything โ Solution: Break into focused, single-purpose Blueprints
Copy-Paste Programming โ
โ Problem: Duplicating similar logic across Blueprints โ Solution: Create shared functions or components
Magic Numbers โ
โ Problem: Hard-coded values throughout Blueprint โ Solution: Use variables or data assets for configuration
Deep Nesting โ
โ Problem: Excessive branching and nested sequences โ Solution: Break into smaller functions, use early returns
Tight Coupling โ
โ Problem: Blueprints directly referencing specific other Blueprints โ Solution: Use interfaces, events, or dependency injection
This comprehensive pattern guide ensures your Blueprint code follows industry standards for maintainability, scalability, and performance. Apply these patterns consistently across your project for professional-quality results.