Hey guys, Im new to UE4. Im trying to make a puzzle with 4 buttons and three sliding glass doors. The character steps on button1 and doors 2 and 3 open. The character steps on button2 and doors 1 and 3 open. the character steps on button 3 and doors 1 and 2 open. the character steps on button4 and door 2 opens.
If the character steps on a button and the corresponding door has already been opened then the door will close. Can someone please explain a way to test if a door is in an open or closed status?
I have been using a vector adjusting through the timeline to move the doors.
You should be able to use the same timeline and vector as this only handles the ‘animation’ of the doors, before this though you could have a boolean variable for each door (Door1Open?, Door2Open?, Door3Open?) and having them set to True after the doors have been opened and False after the doors have been closed. Then before your play your timeline check to see whether or not the boolean is true or false, obviously if it is true you can end the node flow there as nothing more needs to happen (you could maybe print a string saying ‘door already open’ for debug purposes) if the boolean is false you can then continue to play your timeline to open the door
If your not using one single blueprint to control all of this logic it will be a bit more complicated as you will need to do casting and find doors in the scene (They will not be in the order you imagine them to be) You would need to make a copy of each blueprint door (Door1, Door2, Door3 etc) to make casting a bit easier I guess
You do not need to create multiple doors, you need to create one DoorBlueprint class that derives from Actor and add a boolean ‘isOpen’ to it. I would also create a class for the button.
You will need to get a reference to your door, which might be a bit tricky in this scenario. What I would try is create a ‘DoorID’ integer in the DoorBlueprint and I would initialize that door ID to be different for all instances of the class. This way, when you push the button (which should hold an integer array called ‘DoorIDToOpen’), you can use the ‘GetAllActorsOfClass’ node to acquire a reference to all doors in your level. Then use the ‘ForEachLoop’ node and check if the given array element’s ‘DoorID’ is contained in the ‘DoorIDToOpen’ array. If so, you can open the door and set the ‘isOpen’ boolean to true on it.
If it’s just for opening and closing the door there’s no need to throw variables around and check if the door is open or now.
Have the first output hooked up to your opening animation and the second to your closing animation in the door blueprint and have it triggered by a custom event.
On the buttons you just trigger the events for the corresponding doors. If that’s really all you need, there’s no need to overcomplicate things by checking the door state every time.
Yes, you are right, the ‘puzzle’ word made me assume that he wants to implement some kind of further logic later on with the doors, but based only on his post, the flip-flop is definitely more suitable here.