Use the same variable in two different blueprints

Actually that’s not what you need, if I get it right. What you need is to set an “Open Door” function in the Door BP and call this function when the Button is pressed.

Hello, i’ve got a problem with two blueprints that should communicate.
I’ve got a buttonBP and a doorBP, when you press the button the door have to open.
The variable wich says if it’s open or not is a boolean and works perfectly in the buttonBP, so the doorBP should read this variable and open the door if it’s true…but I have no idea how to call the variable within the blueprints.
Thanks for the help in advance.

And how can i do that? Now I’ve create a function in the doorBP but I don’t know how to call this function in the buttonBP

You’re going to use buttons and doors in various levels, I assume.


In this case I’d say the best solution would be to create an event in the Button BP and call it whenever the button is pressed. Next, in your Level BP you Bind to that event on Begin Play, and then you execute the Door function.


Don’t mind the purple “Button” output pin, you won’t have that in your Custom Event node. In my case the event goes with the button tag — it allows using one Bind Event node for multiple buttons.

259755-button.png

personally i would go with direct blueprint communication since its relatively simple and is modular. to use this approach you will have the button call a custom event on the door to open it. to do this though will require a reference to the particular door you want to target, to get this reference we will use a public variable.

to implement this system we will begin by creating a door bp, i named mine DoorTest in this example. in the doortest bp create a custom event “OpenDoor” and script your functionality to have the door open. next create your Button bp (button in the example). in the button bp create a variable (DoorToOpen) and set its type to doorTest, this is done in the details panel as shown below. next at the bottom left click the eye icon next to the variables name so it appears as an open eye, this makes it public and allows you to set its value in the level editor window later. now we just need to create the script to use the button and call the open door event. in the example i used the E key to use the button, then i got the variable and dragged off it and searched for the openDoor event.

now to actually using the doors in your level. place a door in the level then place a button as well. when you select the button in the level, if you look at the details panel in the default section you will see the variable you created earlier. if you click the dropdown it will show you a list of all instances of the door bp in the level, you can use this to set the variable to a specific door or put another way you are setting which door to open aka setting the target.

using this method you can have as many doors as you like and as many buttons too. as long as you remember to set the variable for each button to the door that it corresponds to. this system also will enable you to have multiple buttons control the same door if you wished. also this is the most basic form, you could add in some loops and arrays if you wanted one switch to control many doors. oh one more thing to note, if you are going to use a simple button input like shown you may run into a priority issue so you may need to add in a bit more functionality to control the input but thats a pretty simple thing too and i can explain it if needed.