• News

• Industries

• Learning & Support

• Community

• Marketplace

# Simple Door and Key System, and I'd like to build a complex system next...

I created a simple door and key system, using generic assets of a cone to represent the key, and a cube to represent the door…

This works pretty well so far, and accomplishes the following:

• If you try the door without grabbing the key, it tells you that you need to get the key.
• If you grab the key, it assigns the variable saying you now have it, and then destroys the cone that acts as the key. (Representing the key pickup.)
• Once you have the key, if you try the door, it destroys the cube that acts as the door. (Representing the door opening.)

Now, my challenge is this: Is there a simple way to have multiple keys on a level that corresponds with specific doors? (i.e. I have key 1, 2 and 3, which open door 1, 2 and 3, respectively.) I have been trying to work through the logic that says the following:

• If you try any of the three doors and have no keys, it will tell you “you don’t have a key”. (Sure, I could cheat and say “you don’t have the key for THIS DOOR”, but that would be a cop-out.)
• If you have one key, and you try the wrong door, it will tell you “this is not the correct key for this door”
• If you have more than one key, and you try the right door, it will tell you “none of the keys you have open this door”
• If you have the right key in your inventory for the door, it will open (or destroy, in this case) the door

Shy of building (what my brain can only comprehend are) giant blueprints for each of the keys and doors, is there a simple way to make this work? I can think it through, having multiple branches and multiple outcomes, but I think there may be a better way to do this…

I was considering trying to determine if each ‘key’ could be assigned a unique value so that any combination would add up to a specific total which would tell you which keys you had, and then this calculation could be applied to each door itself.

For example:

• Key 1 is worth 1
• Key 2 is worth 3
• Key 3 is worth 5

So… if you owned the following combinations:

Key 1 alone, the total would be 1.
Key 2 alone, the total would be 3.
Key 3 alone, the total would be 5.
Key 1 and 2, the total would be 4.
Key 1 and 3, the total would be 6.
Key 2 and 3, the total would be 8.
Key 1, 2 and 3, the total would be 9.

Am I thinking too much here? Obviously, having only three keys wouldn’t be as confusing as having ten keys and ten doors, but would something like this work? Is there something much better than this, that could accommodate what I’m looking for?

Rick

Maybe I’m missing something, but why don’t you just have an array of ints instead of trying to some sort of base 3 addition thing you’re thinking about doing? Give your keys and doors an int variable, and when you pick up a key, add that keys int to your array off picked up keys.

Ah, that’s a great idea! I’m just starting out, and wasn’t aware there was an integer system built in. I’ll do some research and see what I can find, thanks!

Well, Ispheria beat me to it - that’s exactly how I’d do it

Great minds think alike, I say! Thanks for chiming in!

I am struggling to figure this out, but it hasn’t beaten me yet! I’ve configured a “Key Owned” array, and am challenged by how to utilize it and feed it data. My logic tells me:

• Each key trigger should be assigned a value which corresponds to the key number it represents being picked up
• Each door trigger should be assigned a value which corresponds to the key permitted to open that door
• Once the key is triggered, it should pass the variable attached to it to the “Key Owned” array, adding it to the list of keys held
• Once the key is added to the list, the next process should read in the last passed value, and destroy the appropriate key’s actor
• When you approach a door and trigger it, it should compare its own value to the list in the array, and determine whether or not you have the appropriate key (If your key list is empty, no-brainer message - “you ain’t got no danged keys!”) and give you the message
• If you have the correct key, the process will destroy the door’s actor

If anyone has examples of the basics of assigning variables, passing them, and adding/modifying/deleting array variables, I would love the recommendations. (In the interim, I’m soldiering on!)

I appreciate the help, thanks!

Rick

**NINJA EDIT - **Currently reviewing this link: https://docs.unrealengine.com/en-us/Engine/Blueprints/UserGuide/Arrays

Here, I decided to just make a video for you.
https://youtu.be/nlleXQIAIAA

yes I m relatively new with the engine but I have a similar setup which uses an array. set the variables public , so you can specify which key you want to open the door . that is each door bp you set on the level.you can swap In any mesh you want to represent the door or the key on an overlap event.

Sir, thank you! As I had mentioned, I’m just learning the editor, and actually haven’t touched coding in something like fifteen years. I wasn’t aware of the mistakes I’d been making, but in the first minute of watching the video, I’ve already learned something new.

I am watching the video now, as we speak!

Thanks again!

Rick

**NINJA EDIT **- Holy heck, sir. That was amazing information, thank you! I am very excited to get working with this now and see so many amazing ideas that this simple design can work for. It’s perfect to track multi-level inventory, simply by adding additional arrays (if warranted) for keys, items, potions, magic items, etc. etc. THANKS AGAIN!