I need advice on how to implement resource system for RTS build system

Hi there,

I am currently working on an top-down survival game. One of the core features will be build system which I already have working decently for the prototype. What I am implementing now is a resource system:

-Every building prefab has cost script attached which defines the cost of the building.
-The resource system needs to be constantly in the HUD for the user to see.
-The user should only be able to build a building if he has sufficient funds.

My idea is to have an empty game object called Resources. The resource manager script would be attached to this object. The resource game object then has child objects for each resource in the game (Timber, Steel, …). Each child has the resource script attached. The resource manager keeps track of a list of the resource game objects while the resource script stores the value and has function to manipulate the value of the resource.

Then the building cost script could access the list of resources and compare their value with it’s own cost vector determining if there are sufficient funds or not. If there are funds then the resources will be removed once the building prefab is initialized.

The resource manager script is also responsible for displaying the resource values to the user through GUI.

I am wondering if this implementation makes sense because I feel it’s a little bit complicated for this simple task and would love to hear if anybody knows how to do this more efficiently.

look into singletons, you could have a resource manager and then when you build a building do something like resourceManager.instance.material -= building.materialCost etc

1 Like

I guess I could also use a hashmap with name of the resource as a Key and then the value is the current amount of that resource. Then I only need to store the name of the resource and the amount in two seperate arrays in the building script and then I can just access the hashmap from the singleton to get the value of each resource.

This way I could get rid of the resource script and the specific game objects for each resource.