Context
I’m trying to write my quest system and here’s the basic structure for a quest:
- A quest is a C++ UObject that is composed, among other things, by objectives
- Objectives are also UObjects. There is one base abstract class that represents an objective, and derived classes that represents objective types, such as reaching a location or killing an enemy.
I then created multiple blueprints extending my base quest, and due to the way I exposed the quest variables and objectives, I can use the editor to setup everything up for each quest and they are only instanced once the player accepts it. I have one blueprint for each quest in my game and so far it seems to work well.
My question
I’m now trying to save/load the quest state. My initial thoughts are to create a TMap in PlayerState and store the quest states in there (saving only the bare minimum, like what is the index for the current objective for a quest, how many enemies the player has killed already, or if the quest has been completed already).
While I could use the blueprints class for each quest as the key in TMap, that sounds like an overkill, so I was trying to find a way to automatically generate a ID for each quest in a consistent way, meaning that every blueprint quest class needs to map to a unique ID and it needs to be the same ID every time as I need to save this information and be able to retrieve it in a different play session.
My idea was to use the GetTypeHash
function using the class name of each quest to generate an integer ID, but I don’t know how the hashing function for strings work in unreal or what are the changes for collisions.
Is that a good approach? Are there any other approaches I could consider?