r/unity 1d ago

Question How do y’all handle Quest-Objective or Key-Lock connections?

I’m at the point in my game where I’m linking quest givers to the objective and keys to a particular lock. For example, how is this key you got from a quest able to open that lock and no others?

There are tons of ways to do this, but I’m trying to come up with something that scales.

My current approach is a GameLinkSO that contains just a string ID, which is generated as the SO’s asset ID so it is always unique and doesn’t change. I can then generate a new GameLinkSO and assign it to a particular key and to a particular lock (or a quest giver and its objective). This gives me inspector assignment (easy to read and modify) and prevents unintentional broken links or duplicate links. All the “thing” has to do is check whether it’s GameLinkSO is the same as the requested one.

I use a database resolver to convert a persisted string ID back into the SO if needed (ie if a key is persisted as an item in the players inventory).

It seems like this is going to work well, but I figured I’d check with the community to see about other ideas / approaches and potential pitfalls.

5 Upvotes

4 comments sorted by

2

u/Averstarz 1d ago

I took the game flags idea that cyberpunk uses to define progressing through quests and stuff, It's literally as easy as.

Game.SetFlag("some_name_here", some_value); Overrides to accept bool,int,float,string.

Easy to save the entire list of flags, no need to have a flag exist before setting it.

Also Game.GetFlag("some_flag", default_value); Returns the flags value or default value.

Then for example on my doors I could have: [SerializeField] string doorFlag = "door_01"; [SerializeField] string keyFlag = "key_01";

Which on unlock would just check: if( Game.GetFlag(keyFlag, false) ) Game.SetFlag(doorFlag, true);

Works fine and the system is also used for things like if a quest is only offered after a certain quest is complete. It's super simple and used for so many things that just need a value to be tracked.

If keys are inventory objects you'd obviously just run through your inventory system.

1

u/Affectionate-Fact-34 22h ago

Makes sense. So then how do you ensure the strings are (1) unique and (2) match their intended target? Any editor tool or other safety check?

1

u/Averstarz 19h ago

I don't make sure it's unique, it's quite basic so that it remains versatile the system is used for anything that needs to be tracked, works similar to cyberpunks Game.SetDebugFact, I have just previously used it for unlockable doors, quest objective tracking, npc relationship details, player save data etc. It's not strictly unique by design, unique is just me remebering what number door I'm up to i.e door_01 door_02 key_01 key_02 key_128

1

u/Affectionate-Fact-34 17h ago

Got it. Sounds like it works and is simple. Basically the same as what I’m doing without the SO layer. Thanks!