# Using string hashes for indexing quest state in TMap

**URL:** <https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865>\
**Category:** Architectural and Design Visualization\
**Tags:** unreal-engine\
**Created:** [October 8, 2021, 7:04pm UTC](https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865 "2021-10-08T19:04:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![reisandbeans](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/reisandbeans/32/88718_2.png) [@reisandbeans](https://forums.unrealengine.com/u/reisandbeans)\
**Post date:** [October 8, 2021, 7:04pm UTC](https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865/1 "2021-10-08T19:04:41Z")

</div>

**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?

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [October 8, 2021, 10:11pm UTC](https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865/2 "2021-10-08T22:11:30Z")

</div>

Type hashing could work.

But you can also use Guid structure as a Key in the map and have a _Guid ID = NewGuid()_ in your quest objectives to identify them.

---

<div class="post-metadata">

**Author:** ![reisandbeans](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/reisandbeans/32/88718_2.png) [@reisandbeans](https://forums.unrealengine.com/u/reisandbeans)\
**Post date:** [October 8, 2021, 11:04pm UTC](https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865/3 "2021-10-08T23:04:39Z")

</div>

GUID will vary between gameplays, I believe, and everytime the quest is instanced it will have a different ID. I was looking for a way to get the same ID everytime.

One of the reasons for that is that I intend to have quests that depend on other quests to be complete. If I can consistently map a quest to an Id, then when I’m creating a “child” class, I can provide the class of the quest it depends on, map that to an ID and query my state map if the desired quest has been complete already, for example

---

<div class="post-metadata">

**Author:** ![and-rad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@and-rad](https://forums.unrealengine.com/u/and-rad)\
**Post date:** [October 8, 2021, 11:29pm UTC](https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865/4 "2021-10-08T23:29:33Z")

</div>

Guids will stay consistent if you store them in a UPROPERTY(EditDefaultsOnly) variable. When you create the Blueprint, you can assign a new guid to that property and it’ll stay that way just like any other property you set in a Blueprint asset.

Depending on your long-term plans, it might also be worth looking into primary asset ids. They work well with the Asset Manager, which is something you might have to consider 2 years from now when you have 200 quests you need to load without causing the framerate to suffer.

---

<div class="post-metadata">

**Author:** ![reisandbeans](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/reisandbeans/32/88718_2.png) [@reisandbeans](https://forums.unrealengine.com/u/reisandbeans)\
**Post date:** [October 8, 2021, 11:52pm UTC](https://forums.unrealengine.com/t/using-string-hashes-for-indexing-quest-state-in-tmap/254865/5 "2021-10-08T23:52:27Z")

</div>

Asset ids look promising! I wasn’t aware they were a thing. I’m fairly new to unreal engine still trying to get used to all the available tools.

Thanks!
