Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

Product Version: UE 4.16
more ▼

asked Aug 06 '17 at 05:34 PM in Blueprint Scripting

avatar image

3 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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. :)

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!!

more ▼

answered Aug 07 '17 at 02:40 PM

avatar image

562 18 24 41

avatar image cvtsdmn Aug 07 '17 at 07:23 PM

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" one

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

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. three

avatar image Fjellgnu Aug 07 '17 at 09:08 PM

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.

avatar image cvtsdmn Aug 08 '17 at 01:02 AM


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.

avatar image Fjellgnu Aug 08 '17 at 02:08 AM

You are most welcome!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question