For my game (Nocturnal Throne) I needed a way for players to unlock new items. The idea I had in mind was a challenge system where the player completes certain challenges and they can get a reward. So I needed not only a way to store different challenges, their names, descriptions, etc, but also needed to assign a value to them (like number of kills, or deaths, or jumps).
So I had very few ideas in mind with how to manage such a system. I mean how can I keep track of so many different values, whilst also keeping it modular?
My first idea was to have separate variables for each stat I wanted to track. The downside of this is it's not very modular at all, I would have to make a custom function for every possible stat type and this is just not viable.
So my next idea was to use maps. These let you store a key, and a value in a long list. So you can have many keys, and many values. This is perfect for tracking stats.
So an example of this for kills would be: Key = "Kills", Value = 352
Another good reason to use maps is that you don't have to manually assign keys. You can assign them at any point in a blueprint, and only one of the same key can exist, so you don't have to worry about any overlaps.
So we have the map setup. We need a way to modify the map through blueprints. So I created an interface that takes a key, and value as an input.
So then we just check in the game instance if the key exists, if it does exist then we just add the "Value" to it. If it doesn't exist, then no worries since we can just set the value to be whatever the value in the interface was.
Now I needed a way to store information about the challenge. So I just created a data asset for it, where we store any relevant information and assets we may need.
I also added a counter that displays what the current value of the stat is, which just finds the key and value from the game instance.
Overall, I'm extremely happy with the system and its modularity. I was really struggling for a week or so to come up with a reasonable idea on how to manage so many different stats, but this seems to work.
I also added a function that allows me to brute force the completion of a challenge, for the ones that don't require any kind of stat tracking. Such as finding a secret location. Again, this is still an interface so no extra functions required.
Back to Top