Now that we have created our collectables and door, we are going to combine these two elements to create a unlockable door that can be opened when the player has gathered all collectables.
While we could manually set the amount of collectables needed to open the door, we are going to have unreal engine count the amount off collectables in the level at game launch instead.

In the Content Drawer search for “BP_ThirdPersonGameMode”. Double-click to enter and open the Event Graph.
As you can see, we are already using Event BeginPlay. So that we can execute multiple functions we need to add a sequence.

Drag and release from Event BeginPlay. Type and select “Sequence”.

As we want to count the amount of collectables in the scene before loading the HUD, connect the previous node chain to “Then 1”. We can now start our new node chain.

Drag and release from “Then 0”. Type and select “Get All Actors Of Class”. Set the actor class of this node to BP_[Item]Collectable (or whatever you named your collectable blueprint).

From the new node, drag and release from “Out Actions”. Type and select “Length”. This allows us to make the number of keys in the scene into a number we can reference later.

From the new Length node, drag and release. Select “Promote to Variable”. Name this variable “[Items]Total” in the Details Panel on the right. Connect the Get All Actors Of Class node to the [Items]Total node as shown.

We can test if we are successfully counting the amount of collectables by dragging and releasing from the top-right arrow of the Set node.

Type and select “Print String” and connect the mint green and magenta open connections. The Event Graph should look like this.
Compile and test. If successful the number of collectables in the scene will appear in light blue will appear in the top left corner immediately after you pressing play.

Now we need to visualize the total number of keys in the scene. From the Content Drawer, search for “WBP_HUD” and double click to enter it.
In the Widget Designer select the existing textbox and press CMD + C to copy it. Paste it back twice using CMD +V.

Change the middle text box to a slash in the the Details Panel on the right under Content > Text.
Select the rightmost checkbox and rename it to [Collectables]Total. Click the chain link next to Content > Text and click Create Binding.
Now let’s head to the Widget Event Graph.

We now need to add a sequence node to the Event Graph, as we did before. Drag and release from Event BeginPlay. Type and select “Sequence”.

As we want to load the number of collectables in the scene before loading the HUD, connect the previous node chain to “Then 1”. Drag and release from “Then 0”. Type and select “Cast to BP_ThirPersonGameMode”.

Drag and release from the object parameter of the new node. Type and select “Get Game Mode”.

Right-click the As BP Third Person Game Mode parameter of the Cast to BP_ThirPersonGameMode node and promote to variable. Name this variable “GameModeReference” and connect as shown above.
Compile and test, your HUD should now display the total amount of Collectables in the scene at the start of play.
Now to create our unlockable door.

We are going to use the regular door blueprint we created in the last tutorial as a base for our unlockable door. In the Content Drawer, right click the “BP_Door” and select Duplicate. Rename the duplicated door to “BP_LockedDoor” and Double-click to enter the Event Graph.

Right-click the pressed output of the “E” Input node and select “Break This Link”. Drag the separated chain to the side, we will need it later. Drag from the “Pressed” output and release. Type and select “Sequence”.

We need to get information about the items Collected and items Total from different blueprints. From separate outputs of the new sequence cast to “BP_ThirdPersonGameMode” and “ThirdPersonCharacter”. In the Objects input of each node, Get “Game Mode” and “Player Pawn” respectively. It should look like the image above.

From the bottom-right blue arrow of each new node, drag and release. Type and select “Get [Items] Total” and “Get [Items] Collected” for each respective node.

Drag and release from either new node. Type and select “Equal (==)” and connect the other node. This will activate the chain when the total items and item collected are the same.

Create a branch node by holding “b” and clicking a blank area of the Event Graph. Connect to the Equals and Cast to BP_ThirdPersonGameMode nodes as shown above. We can now reconnect our door opening chain to the “True” output of the new node.

Your Event Graph should look like this. Compile and test. Your locked door should only open when all keys are collected.