Use the same variable in two different blueprints
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.
asked Nov 18 '18 at 03:18 PM in Blueprint Scripting
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.
answered Nov 18 '18 at 07:03 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here