how to make an if statement?

Hi everyone, I am creating a game with my friends for my school. We would like to create something like an escape room. Now I am creating some new mechanics and I have a problem with one of them. I want to make a puzzle where the gate opens when the clock shows the correct hours and minutes (right now it’s just a prototype, so I’m using the stairs instead of the clock, and the box is the gate). I’m new to UE and don’t know how to make this if statement so that the condition checks the rotation of the clock hands. Thanks for any answer.



1 Like

Does the rotation of the stairs BP actor change, or the stairs within the BP?

A basic if statement is made with a branch node. Just hold B and click somewhere in your blueprint.
If you want to check constantly for a condition, plug your “event tick” into the branch node to check constantly.
Based on your code, I think what you want to do is instead of having two events for begin overlap, you can optimize and compact your code by just having a branch node come off of your keypress E node that checks if the box has any overlapping actors, by using a “get overlapping actors” node with a filter for whatever class you’re checking for so that random things (physics objects, etc.) don’t trigger it. off of that just add a “is empty” node for the array it generates, and plug that into a branch, and you should be set there.

As for checking the rotation, just get the reference for your stairs and get the relative rotation, drag that off and make an “equals” statement (on the other pin just add whatever value your goal is), and then plug that into a second branch node (this one connected to your tick event), that sets the location/rotation of the box off of the false and true pins of the branch.

believe it or not, it took me about a month to figure out how to do an if statement in UE, so you’re not alone there. Good luck with your project!

I hope this helped,
ShakeATower4

1 Like

Thanks! I’ve had a long break from the project now and I hope with your help it will take me a lot shorter :smiley:

When we click on one of the two buttons, we rotate the stairs assigned to them (left stairs to the left button and the same to the right). I would like the script to check the rotation of the stairs and if it equals the number in the if condition (e.g. z.axis=40 for left stairs, z.axis=20 for right stairs), the cube between them will rise.