Moving by clicking a button

Hey guys,

I create a widget with a button in it. I use the sidescroller example for testing things. I dont get it working. By clicking the button the character should move right. I tried a lot of different things. How should the blueprints look like to get it working. I would really appreciate your help!



Is there any way to setup a button as an input key?

Have you tried having the button press event call a function on the character, which performs the movement logic?

So here is the movement blueprint. How can get the player move right by clicking the button?

In the character, add an event. Hook it up to the add movement input. It should look almost as it does now, but instead of a input axis event, it’s your custom event.
Set the scale value to 1 in the add movement input node.
Now, in the widget bp, drag off the character node and call your custom function.
That’s it.

Thought the same but it does not work. Do you see what ist wrong?

Yeah, you’re getting the playercontroller and casting it as character. It fails.
Get player controller - get controlled pawn - cast as sidescrollercharacter.

Thank you! It works now!

But the event is just called one time. I have to click thousand times to move the character. I thought the event is called all the time until I release the button. Sorry my english is not the best. I hope you can understand what I mean.

Okay. So now that there’s basic functionality, you can change it to be more practical. Instead of calling the movement input directly from the function, you can set a boolean.
And you need to add a ‘on release’ event on the button, which sets the boolean to false.

And each tick, you check the boolean. If it is true, call the movement input.

I understand what you mean. I try it out tomorrow. Thank you!