top of page

Technical Design Exercise Part 1: Entity Resource

Writer: Alex Gadda
Alex Gadda
Aug 13, 2025
4 min read

Updated: Aug 14, 2025

Overview

I decided to challenge my skills doing some technical design exercises (and also to take the opportunity to enrich my portfolio!).

The following exercise is taken from this very useful article by Artyom Volkov:

A second part might come soon!

I'm using Unreal Engine 5.6 with the third person template.


Ex.1 - Entity Resource

Assignment

Create a basic component called EntityResource which can be used for quick implementation of various resources to the game, such as:

  • Health

  • Mana

  • Stamina

  • Overheat

  • Etc.

The component should have these parameters, functions, and callbacks.

Parameters:

  • InitialValue. Determines CurrentValue of the resource at the start of a game.

  • MaxValue. Determines MaxValue of the resource.


Functions:

  • IncreaseValue. Increases CurrentValue of the resource on a given amount. It can’t increase CurrentValue more than MaxValue.

  • DecreaseValue. Decreases CurrentValue of the resource on a given amount. It can’t decrease CurrentValue less than zero.


Callbacks:

  • OnValueIncreased. Called when CurrentValue was increased.

  • OnValueDecreased. Called when CurrentValue was decreased.

  • OnValueZero. Called when CurrentValue reached zero.


Create a HealthComponent inherited from EntityResourceComponent.


Challenges:

  • Update IncreaseValue function. Add an option which allows increasing CurrentValue more than MaxValue.

  • Add new functions:

    • IncreaseMaxValue. Increases MaxValue on a given amount.

    • DecreaseMaxValue. Decreases MaxValue on a given amount.

  • Implement auto-decrease functionality. CurrentValue should decrease automatically to MinThreshold with a given rate if CurrentValue > MinThreshold. For example:

    • MinThreshold = 100.

    • CurrentValue increased from 25 to 200.

    • CurrentValue automatically starts to decrease to 100 with a rate of 5 resource per second.

  • Implement auto-increase functionality. CurrentValue should increase automatically to MaxThreshold with a given rate if CurrentValue < MaxThreshold. For example:

    • MaxThreshold = 50.

    • CurrentValue decreased from 100 to 5.

    • CurrentValue automatically starts to increase to 50 with a rate of 5 resource per second.


Parameters, Functions and Callbacks

I've decided to implement EntityResouce in C++ as an ActorComponent.

AC_EntityResource.h:


AC_EntityResource.cpp :

To test the implementation, I've added the component to Unreal default third person character:


Result:


Health Component

Since no further details are provided for this part of the assignment, I’ll move on with the challenges.


Challenge - Overflow

Update IncreaseValue function. Add an option which allows increasing CurrentValue more than MaxValue.

I decided to add an optional parameter to the function:

During testing, this small change actually highlighted a problem with the implementation of the 2 functions: if you increase the Value over its limit, the DecreaseValue function will bring it back to the max value (as the result is clampled).

I adopted a simple solution to improve both functions:

Problem: this solution is still partially wrong, as if the CurrValue is overflowed, the next increase with bAllowOverflow = false will reset it to max Value!

Corrected version: in this version, we skip the assignment if the value is already higher than MaxValue.


Challenge - Increase Max Value

Add new functions: - IncreaseMaxValue. Increases MaxValue on a given amount. - DecreaseMaxValue. Decreases MaxValue on a given amount.

Naive solution:

The second function, however, presented a clear problem: if I decrease the MaxValue below the CurrValue, it's value is not actually updated!

Solution:


Challenge - Auto-Decrease & Auto-Increase

Implement auto-decrease functionality. CurrentValue should decrease automatically to MinThreshold with a given rate if CurrentValue > MinThreshold. ...

This assignment might be interpreted in different ways, depening on the use. It might be:

  • A way to decrease the HP of an ally after they have been over-healed (using the Overflow implemented before).

  • Or to increase/decrease HP / Mana over time for healing / sapping / poison effects.

  • Etc...

As I feel both might be useful, I’ll start with the first one (which is a much closer interpretation of the assignment), then I’ll also do the second because it sounds like a fun challenge.

Solution:

I've used EditCondition to make it clearer that Min and MaxThreshold have no effect if the corresponding boolean variable is set to false.

View from the Details panel
View from the Details panel

Result, with MinThreashold = 100 (to simulate overhealing HP) and MaxThreshold = 10:

Note: these function might be a little unsafe if the Thresholds are set over the limits.


Bonus Challenge - OverTimeEffects

I want to make a system that let me add effect to increase or decrease the CurrValue over time (e.g. healing, sapping, poison effects...).

It should let the user choose:

  • A ChangeRatePerSecond: : how much to change the CurrVale. Can be both positive or negative.

  • A Duration: when reaches 0 the effect stops. If set to a negative number the effect is permanent (until removed).

  • If CurrValue can overflow.

Also, it should be possible to have multiple effects over time active at the same time.

My idea was to use a list of OverTimeEffects structs and check it during tick to update the current value.

At this point, I realized that having a float value is simply... a very bed idea : modifying a float value over time, without knowing the exact ending value beforehand, causes unavoidable floating-point errors!

This can lead to a poison effect that should deals 2 dmg/s over 5 seconds, to not kill a player with 10 HP! Or worse, to a weaker poison effect to kill it!

A solution: just use integers!

I didn’t consider this solution from the start, because floats are often preferred for their greater flexibility. In this case, however, it’s better to have a precise number that can be represented just by a larger integer. If we want the UI to update in a more

Clearly, this is not a perfect solution. But in game dev there are never perfect solutions, only decision that brings us closer to our goal.

Inside Tick() the auto increse/decrease becomes:

I'm using accumulators to reach a numbers grater than 1, to then be able to increase or decrease the CurrValue by a unit.

I began implementing effects over time by defining the base data structure that holds the effect information. FOverTimeEffect struct:

These effect are added to a list (TArray<FOverTimeEffect> OverTimeEffects) via this function:

Then, I simply checked the list for active effects during Tick:

Result:

Conclusion

Total work time for code and presentation:

4.5 hours + 2 hours for the bonus exercise.


 
 
 

Comments


bottom of page