Creating a Problem Solving System in UE4 (2/2)

Ali Siddiqui
code3100
Published in
4 min readApr 3, 2017

Another aspect we wanted to have in our game was getting the player to move around and explore the space. To achieve this, we thought one of the challenges would involve the player needing to find all keys to unlock a door. This will allow the player to get used to moving around in a virtual environment.

My Goal: Create a door/portal that can only be accessed if the player collects all the keys.

Step 1

I made two Blueprint actors, the first being a door static mesh which will act as the portal to the next stage. The second was a sphere static mesh that will be the keys that the player must collect to be able to go through the portal. Next, I created a blank map that will be where the player teleports to after going through the portal.

Assets described above
Sphere actor used as a key
Door actor used as a portal

Step 2

Then, I create a variable in the Character Blueprint called ‘NumberOfKeys’ that will be an integer representing the amount of keys needed to unlock the portal. This variable will be referenced in the portal and key blueprints. I also created a GameInstance Blueprint which will be used to save data between stages e.g. portal requires 3 keys > player collects 4 > player goes through portal > 1 key remaining in player inventory.

NumberOfKeys variable as an Integer

Now I start making the script in the Key Blueprint. A simple collision trigger is used where if the player overlaps the sphere collision, this data is sent to the Character BP and is added to the ‘NumberOfKeys’ variable. The key actor is then destroyed to show that the player has collected it.

Key Blueprint script

Step 3

Next, I start working on the Portal Blueprint script. I add a collision trigger event that sends this information to the Character BP and allows me to use the ‘NumberOfKeys’ variable in this script.

Casting to Character BP and using required variables

I have to add a new Integer variable in this script called ‘RequiredNumberOfKeys’, this will let me have different requirements for different portals through the use of booleans and true/false statements.

Using new variable to check if player has sufficient amount of keys

The script above works as follows:

  • Does player have required amount of keys? if true > does player have more than required amount of keys? if true > subtract required amount of keys from the amount of keys picked up > send this information to GameInstance and save data in the following stage > open new level
  • Does player have more than required amount of keys? if false > send this information to GameInstance > open new level
  • Does player have required amount of keys? if false > print “You Don’t Have Enough Keys!” > don’t open new level

In-Game

Start of first stage
Only ONE key picked up, TWO required to enter portal
‘Don’t have enough keys’
All THREE keys picked up
Portal teleports player to next stage
One key remaining in inventory
Number of keys required and stage name can easily be edited

Learning this simple game mechanic was very helpful in furthering my knowledge in the communication of information between Blueprint scripts as well as saving data to the character itself. This can be further developed and used for our final game.

--

--