Godot Version
4.6
Question
Sorry if this is already answered - I searched and was not able to find something close to what I am asking about.
What are the best practices for managing resources throughout a game?
I’m interested in the mechanics more than gameplay at this point, but I’ll take any advice.
I’ve broken my question into a few separate areas:
Basic Scenario:
Let’s say I have a single player game, with 10 levels.
Each level has resources like pickups, treasure, tools, etc.
When a player picks up a resource, it will disappear from the level.
When they save the game, the current resource status is also saved, and reloaded when they restart.
This would be tracked using an array.
All basic concepts, but many ways to implement.
Initial resources setup:
When setting up the game, I could do several things to place and track the resources:
- I could manually place each resource node and manually enter the item/position into a default array.
- I could manually place each resource node, and in code, when the game first starts, read each node and fill an array.
Either way, I would then use that array (or better yet, a duplicate) to track the resources during game play, saving, etc. An array of dictionaries would give me the ability to track metadata for each resource (used/unused, etc.)
I lean towards the second method so I can visually place the items at design time, move them at will, and never have to manually mess with the resource array.
Plus, if I use a duplicate array, I could always refer to the ‘default’ resource map.
Is there a better way?
Managing the array:
When a resource is picked up, is it better to set the corresponding array item to null, or just change a flag on the item indicating it’s been used?
Is there a better way to do this?
Inventory:
I’ve seen some inventories that manage the resources directly, but it seems reasonable to me to use the array to add/remove resources, and somehow link the array to the inventory.
What is the better/common way to do this?
If there’s a guide somewhere that addresses these basics, I’d really like to read it.