How to do a password numpad

Hello there!

I have a big doubt, I did a numpad to introduce a password for my game, but I just realized that I don’t really know how to click this buttons and take the information in the blueprint to check the combination. I already did the linetrace from the character, but I need to know how to click the different buttons.

Waiting for your answers, thank you!

Create a base “Button” actor with a variable to store your button number and have your keypad numbers inherit from this actor. Add these new buttons to your keypad, changing the number variable for each one, respectively. From there, you can use [Is Clicked] nodes to determine if your player has clicked on this actor. It’s important that the [Is Clicked] be triggered in reference to that button’s instance because you would otherwise keep triggering the original instance.

I highly suggest checking the trigger from the keypad’s blueprint, using the events that trigger when a child actor of this actor is clicked. Then, you can simply check the button number using a reference to the child actor that was clicked. If need be, add another text component to the keypad and add asterisks for each key press; the actual number can be appended to a hidden/private variable, in the keypad actor, that doesn’t send to the other players.

[Edit]: As a side note, you could use [Get Hit Under Cursor by Channel] in your mouse click event graph. From there, you would use [Break Hit] and pull the (Actor) pin to check which object, or actor, was pressed. IMO, this is not the right approach when you could have the keypad handle clicks on child actors.

Yes-- it’s as simple as a drag-and-drop, or using the “Add Component” menu. Once they are added as child actors, you can change their variables and they individually become the numbers you need for the pad.

What do you mean by “adding these buttons to the keypad”? Do I add them as child actors?

You can use player controller to Show Cursor and Enable On Click Events. then click the button in the component list with ppm and choose Add Event → On Component Clicked and attach your logic to the node that appeared. Repeat for every button. You can store clicked numbers in the string , create empty variable and append it with selected numbers, then check if string is equal to the string you want.

I’m going crazy, I can’t change or even see the variable of the button. What am I doing wrong?

In the button actor, did you click the yellow “eye”-con to make the variable visible?

You can also instantiate and access the variables via blueprint by unchecking “Context sensitive”, search for the variable’s name, then use [Set] while referencing the button’s instance.

I can’t link the node because it says that a child actor cannot be connected where a NumPButton (name of the actor) must be.
And yes, I checked that my variable is public or visible. Is this a bug or you cannot ever touch a variable from a child actor? :frowning:

Use a [CastToNumPButton] between your [Event BeginPlay] and the [Set] node. From there, drag off the (As NumPButton Object) pin and connect it to the (Target) pin of [Set].

Okay, I just did some experiments using [Child Actors] and all of mine will allow me to change [Defaults] in the [Details] panel. I don’t know why yours isn’t showing up. When I click on my [Child Actor] in the menu on the left-hand side, a menu will appear right under [Child Actor Component] (called, [Child Actor Template]) where I can set all of the class [Defaults], including all of the variables attached that will change its appearance, such as text.

I also tried it with a new Actor blueprint, but it’s the same: can’t see my variables. Could it be beause of the Editor version? I’m using 4.13

Well I found out that to connect the nodes, I needed the Child Actor node to cast the Button. If I have to do this nine times, what is the best way to do it? BTW thank you for answering all this time!

You can use a [ForLoop] with [GetAllActorsOfClass], within the scope of your keypad actor, and it can automatically do that for each actor.

Btw, I am using 4.14, so it’s entirely possible that’s why you can’t see the child actor’s variables. I have been using the aforementioned feature to set child actors’ defaults without any problem, without having to set them individually within the graph.

Okay I finally got it. It took aproximately two days but now it works good. Thank you so much for the help!