Hey guys so I have a door mechanic which opens and closes, I also have a switch blueprint which makes it for a power box that the player can interact with via an overlap collision.
I want to know how if I put 3 of these powerbox BP’s accross the map that if all 3 are overlapp interacted that it will open a door, I heard something about Booleans but I am not that good at BP’s, if someone could answer and maybe show some screenshots on how to do so that would be great! I am on UE5.
On the switch, make sure to make the player unable to un-interact with it. Make it a one-way interaction.
In the door blueprint, make sure to have an array of switches that it’s linked to, and a bool for whether the door itself is open. Make sure associated switches array is visible so you can set it in the level editor.
As well as that, also have a bool in the switch bp that records whether or not it’s activated.
The actual action of this happens on tick in the door blueprint.
First, we go through a do-once node- this is reset everytime the door doesn’t open, so the door will only open once. You wouldn’t want a door opening animation to start every frame that the door is open.
Next, we set Open to true. It’s easier to assume true with this node and set to false if it isn’t rather than assume false and set to true.
After that, we go through all the switches associated with this door, and check if any are NOT activated. If any aren’t activated, set open to false, and reset the do-once node.
Finally, after the for each loop has completed, we check whether the door is actually now open. If true, do whatever you want to happen when the door initially opens.
Well you’ll want to add a boolean variable to the switches.
When interacted with it gets set to true or false.
Then when you use the door it can Get All Actors of Class (switch) and check that they all have that variable as true. If they’re the only switches in the level that would work.
But I think you want the final switch to open the door, so that would be a little different.
The type should be “powerbox”.
You can make any type an array of those types by clicking on the shape next to the variable type in the detail panel of the variable.
I notice your detail panel has the variable tab collapsed, so you’ll want to open it to see this.
Make sure to do what’s called camel casing:
Instead of naming it “associatedswitches” name it “AssociatedSwitches” or “associatedSwitches”. With blueprints you can even just use spaces to make “associated switches”.
It makes reading your blueprints much easier.
You drag off the array element pin that’s in the for each loop. A menu will pop up, and in there you search for whatever you named the activated variable in your powerbox blueprint.
You need to create the boolean variable called activated in your powerbox blueprint.
The for each node iterates through all the elements in the array “AssociatedSwitches” that you’ve connected to it. For every switch in the array, it will trigger the loop body. Whenever it does that, the array element will be a switch.
Whenever you drag out from the array element, you’re using a reference to that element. In that search, it will show all variables and functions that object has.
If you were referencing your door blueprint, you’d be able to get stuff like “time to close” “key needed?” “locked” and even “AssociatedSwitches”. You can experiment with this using the “self” node- it references the object it’s in.