Blueprint communication with counters

I think I’ve read all the documentation and posts regarding my question, but the more I read the less I understand.
I need to do (what seems to be) an extremely simple thing, but the more I try the more my mind is blown.
Long story short – There are 4 similar buttons and a door. When the player steps on each button (the order doesn’t matter) the door opens.
Now, what I’ve been trying to do:

  1. I have a button_BP which consists of a physical button and some logic assigned to it through blueprints
  2. I have a door_BP which consists of a physical door and blueprints making the door to open.

I want to create a public variable “ButtonCounter”, and when the player steps on that physical button, it adds +1 to the variable. And when the variable is equal to 4, the door opens.
So first, where do I store that “Button Counter” variable? As I get it, since all 4 buttons are instances of the same button_BP, they don’t share actions made to the variable between them, right? So when I step on all 4 buttons, I won’t have one “ButtonCounter” that is equal to 4, instead I will have 4 separate “ButtonCounter” variables and each one of them will be equal to 1, right? So do I need to store the “ButtonCounter” variable in the door_BP? And how do I actually make the communication between door_BP and button_BP? As I got it after reading the documentation and posts, I need to use “Cast to”, but after all my attempts I failed. I’m not sure why but I just can’t understand how I’m supposed to use it in thins situation. Like, from where to where should I cast in this situation? And what and where that “Object” box in “Cast to” should be? And what’s the difference between “cast to bp_door” and “cast to bp_door class”.
I’m sorry if the whole thing seems stupid. I wouldn’t waste your time if I could figure it out on my own. But I just can’t.

Hello cvtsdmn,

Yes, you should put ButtonCounter variable in door_BP, but you don’t need to cast to anything.

Inside button_BP create a variable and call it something like ref_door_BP and set the variable type to ‘door_BP reference’. Just click on the variable type dropdown menu and search for door_BP and you should find it.

Next you need to activate Instance Editable in the ref_door_BP variable setup.

In door_BP, drag the ref_door_BP variable into the blueprint graph and choose get. Drag a wire from it and search for ButtonCounter. If this does not work try to compile your blueprint and try again. If it still does not work something has been setup incorrectly or I am not very good at explaining this. :slight_smile:

If it works you can place a button and a door inside you level.

If you select the button you can find the variable under Default in the Details tab. Next to the variable is a dropdown menu where you should be able to select the door_BP.

And if this worked you can add more buttons and do the same.

I didn’t have time right not to create screenshots but I can do that a little later if you need those.

Good luck!!

Firstly, thank you so much for helping me.

So, as you instructed, I created a variable “doorRef” referencing “door_BP” in “button_BP” and made it editable. But then you said to drag it into the blueprint graph of “door_BP”, and this is where I don’t get it. I mean “doorRef” variable is placed in “button_BP”, and I can’t drag it into “door_BP” because it’s just not there. So I thought maybe you meant to say to do all that in “button_BP”.
So I did, but in the end I failed. Again.

Let me show you screenshots. I know that what I tried to do is terribly wrong somehow, since it doesn’t work at all (when the button is pressed nothing happens to “ButtonCounter” variable), but maybe if I show you may way of imagining it, you’ll understand what’s wrong with me.

So, this “button_BP” and this is what happens after button is pressed. “DoorRef” is that variable referencing to “door_BP” and “ButtonCounter1” is my button counter variable stored in “door_BP”

Here is my “door_BP”. As you can see, I decided to go with just 2 buttons for now.

And this is what I did in the level. I created two instances of “button_BP” (which is actually called “BP_trigger” in my project, sorry for mislead). And in both instances I selected door blueprint, as you said.

HAKUNA MATATA! IT’S ALIVE!

The thing you told me to do, it worked like magic! Thank you so much, really.
That “Cast to” thing will still haunt me in my nightmares though, haha.

Thank you, again.

You are most welcome!

Whoops, my bad. You should of course drag the DoorRef variable into the button blueprint graph.

And, in screenshot 1 you should change the Set DoorRef node to a Get DoorRef node. Just like the one on the bottom of that screenshot. The way it is now I think you are overwriting DoorRef, making it invalid.