Place blocks in specific places to open a door?

I’m trying to make it so when numbered blocks are placed in their correct spots, 1 door will open. I have made the blueprint for moving the blocks themselves but how and what is the easiest way to make this happen? Pictures help me a lot. Thanks!

Write down the locations of where the blocks have to be, then open level blueprint, make references to all blocks (select block, go to level blueprint) , make event tick, branch, to branch add if the locations of those blocks are equal to where they need to be and if yes, open door.

Here is another method which doesn’t rely on hardcoded locations, and would be more adaptable and reusable.
Also it doesn’t use tick which isn’t necessary for this. It will take a bit longer to set up, but if you ever need to re-use this system it will be a lot easier.

1. Create a blueprint class for blocks, BP_Block

  • Add an int variable, Block Number. Click the eye symbol to make it public.

In my example I have just a Cube mesh with physics enabled that can be picked up and moved around, this will probably be different depending on how you are doing yours.

2. Create a Blueprint class which be placed in your scene and represents a location that a block needs to be placed, BP_BlockPosition.

  • Add int variable BlockPositionNumber. Click the eye symbol to make it public.

  • Add two bools, Occupied, and CorrectBlockPlaced

And a Box Collision component, this will sense when a box is placed in it. Again, this might differ from how you are doing it.

3. Create a new BP class called, BP_BlockController.

This will keep track of how many blocks need to be placed, and how many have been placed correctly etc.
With the way this is set up, you will be able to have as many block puzzles in your level as you want.

  • Add variable array of BP_BlockPosition. Click the eye symbol to make it public.
  • Add int variable, NumberOfBlocks
  • Add int variable, NumberOfOccupiedBlocks
  • Add int variable, CorrectlyOccupiedBlocks

Add a custom event, BlockStateChanged, and the below nodes:

4. Go back to BP_BlockPosition

Create BeginOverlap and EndOverlap events for the box collision.
Add variable, BP_BlockController.
Also on beginplay make it get a reference to the block controller. (If you want to have multiple block puzzles in your level, instead make this variable public, and don’t use get all actors of class, instead set the reference to the right controller directly in your level. There’s no reason to do that if there is only ever one puzzle though)
Set up the below:

The == node on the GetClass should be checking for your BP_Block class

5. Add it all to you level.
So, however many blocks you want, and a matching nuimber of BP_BlockPositions.
Add a BP_BlockController too.
In its details, add elements to BlockPositions, and choose the block positions from the scene.

Now set the ints on the Blocks and the BlockPositions, it should match so that there is a corresponding BlockPosition for each Block.
So if you have a BP_Block with BlockNumber 56, set one of the BP_BlockPositions to also have BlockNumber 56.

1 Like

Any Idea as to why it says the target is invalid?

Try Right clicking on that Cast node, and choose “convert to pure cast”

It worked, thanks a lot! Do you know how I would go about having a door open when the blocks are placed in the correct places?

Great :slight_smile: So, you could create a BP_Door class, give it a custom event that will open it. Add a BP_Door variable in BP_BlockController, click the eye symbol to make it public. Then place a door in your level, and click the BP_BlockController, set the Door variable to point to your Door.

Where the AllPlaced correct print string is in your BP_BlockController, get your door reference, drag off from it and call your Open Door event.

Doing the open door bit would be a separate question but there’s a lot of infoirmation on that online already too. Hopefully this will get you started.

Do you have an image of what that might look like? Sorry, I’m new to unreal.

Also the only string working is not all placed

If that’s the only one working you must have set something up wrong, can you send some screenshots of your blueprint?

In your scene you have set the Block Number int on the boxes, and also on the BoxPoisitons?

But you also have to set the int in the block itself, so in your case you will need 5 blocks, one with the Block Number int set to 3, one set to 9, one set to 1, etc.

If you’ve already done that then I can’t see what could be wrong, if you want to upload the project somewhere and send a link on the forums PM I can check it.

Here are my blueprints. I made sure that each block had a matching position number as well. Yet when I move the blocks to all the right places, the string never pops up.

yes. example: the order for the blocks is 39145. so on position 1 i set the int to 3 and the block 1 int to 3. on position 2 i set the int to 9 and the block to 9, ect.

So it was a mistake with my setup, sorry about that! It could “lose count” if two blocks were in one location and then one was removed. The below fixes it:

Store the current block when it’s overlapped, the only call the state changed function if it’s the same block being removed.


Would the current block variable be type bp block?

It can be actor. reference. Drag off from other acor and promote it to variable

Sweet now it works, thank you so much? now how do I implement the door to work?

Great. In BP_BlockController, add a new variable of type BP_Door. Make that variable editable by clicking the eye symbol.

Where the All Placed Correctly print string is, replace that with a call to your DoorOpen event in BP_Door:

Then in your level, set the value of Door, to be the BP_Door placed in your scene.

The door opening setup you have in BP_Door needs to be changed a bit. Open your timeline and change the graph so that the second point’s value is 1. At the moment it’s 100. Then do this: