Player Resource System
Problem:
In our space-themed adventure game, we required a modular and extensible resource system to handle gameplay mechanics such as:
-
Oxygen levels while the player is in space
-
Thrust consumption during enhanced jumps
-
Potential future mechanics like fuel, shield energy, stamina, etc.
-
​
The system needed to support:
-
Real-time resource decay and regeneration
-
Designer-friendly tuning via Blueprints
-
Efficient runtime performance
-
Rapid scalability for adding new resources without code duplication
Demo:
Initial Implementation
We began with a classic inheritance-based system:
-
BaseResource class → extended by each specific resource type (e.g., OxygenResource, ThrustResource)
-
Each child class handled its own update logic and state management
​
Problems Encountered:
-
High Code Redundancy: Each resource repeated common logic
-
Poor Scalability: Adding new resources meant writing new classes
-
Limited Designer Access: Non-programmers couldn’t easily tweak behavior
-
Lack of Centralization: Resource logic was scattered, hard to debug or visualize holistically
Final Implementation – Component-Based Blueprint System
To address the limitations, we transitioned to a data-driven, component-based architecture using Unreal Engine Blueprints:
​
ResourceComponent Highlights:
-
One centralized Blueprint Component manages all resources for an Actor
-
No need to subclass for each new resource
-
Fully exposed to Blueprints for designer accessibility
System Breakdown:
Key Data Structures: Hashmaps
-
Resources (TMap<FName, float>)
-
Stores current values of all resources (e.g., "Oxygen" → 75.0)
-
​
-
isDecaying (TMap<FName, bool>)
-
Tracks whether a particular resource is actively decaying
-
​
-
DecayRates (TMap<FName, float>)
-
Defines decay rate per resource (e.g., "Oxygen" → 0.1 per second)
-
​
-
RefillRates (TMap<FName, float>)
-
Stores refill rates for resources
-

Key Functions:
-
AlterResource​
-
Either adds to or depletes the value of a resource from Resources hashmap​
-
-
StartDecay
-
Sets the resource's isDecaying flag to true in the hashmap.
-
-
StopDecay​
-
Does exactly the opposite of StartDecay​
-
-
CheckIfAnythingEmpty
-
Checks if a particular resource is entirely depleted​
-

Runtime Logic & Tick Behavior
-
Example Scenario: Player enters space → Oxygen starts decaying
​
-
Input or Event Trigger
-
Function StartDecay(FName ResourceName) is called
-
Sets isDecaying[ResourceName] = true
-
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​​
​
​
​
​
​
​
​
​
​
​
​
​
​​
​
​
​
​
​
​
​
​
​
​
​
-
Event Tick (Per Frame Loop)
-
Iterates through isDecaying
-
If any resourceName is true, calls AlterResource(resourceName, delta)
-
​
​
​
​
​
​
​
​
​
​
​
​
​
​​​​​​​
​​
​
​
​
​
​
​​​​​​​​​​​​​
​
-
AlterResource(FName ResourceName, float Delta)
-
Computes delta as decayRate * -1 or refillRate
-
Adds delta to resources[ResourceName]
-
​
-
Event Broadcast – OnStatsUpdated
-
Blueprint event that notifies UI to update resource HUD values
-
Designer-Centric Features:
-
Blueprint-Exposed Controls: Designers can start/stop decay, adjust values, and visualize state directly in-editor
-
Minimal Setup Overhead: Once the component is attached to the player, adding a new resource only requires naming it and assigning its rates in the component as shown below
​
​
​
​
​​
​
​
​
​
​
​
​
​
​
​
​
-
Debugging Aids: Print statements, HUD elements, and simulation modes built into the component for testing feedback

Performance & Best Practices
-
Used FName instead of strings: Leveraged Unreal’s optimized FName system for fast comparisons
-
Avoided redundant polling: All logic centralized within one Tick loop, avoiding event spaghetti
-
Memory-Efficient: All maps pre-allocated during BeginPlay, reducing runtime allocation cost
Outcome & Benefits
-
Modular: Add or remove resources in minutes
-
Designer-Accessible: Empowered non-coders to control core gameplay variables
-
Maintainable & Scalable: Centralized logic reduced bugs and allowed easy tuning
-
Performance-Aware: Low-overhead system using constant-time lookups and streamlined Tick behavior